@@ -443,6 +443,14 @@ export function getWebviewContentForMat(
443443 return;
444444 }
445445 applyViewState(state);
446+ } else if (message.command === 'setPixelHighlight') {
447+ // Receive pixel highlight from synced panel
448+ highlightPixelX = message.pixelX;
449+ highlightPixelY = message.pixelY;
450+ requestRender();
451+
452+ // Update pixel info display for synced highlight
453+ updatePixelInfoForHighlight(message.pixelX, message.pixelY);
446454 }
447455 });
448456
@@ -511,6 +519,12 @@ export function getWebviewContentForMat(
511519 let pixelTextEnabled = true; // 可手动关掉
512520 let renderQueued = false;
513521 let isShuttingDown = false; // 面板即将关闭时阻断交互
522+
523+ // Pixel highlight for synchronized viewing
524+ let highlightPixelX = null;
525+ let highlightPixelY = null;
526+ let localHoverPixelX = null;
527+ let localHoverPixelY = null;
514528
515529 // Make controls draggable
516530 let controlsDragging = false;
@@ -1054,6 +1068,29 @@ export function getWebviewContentForMat(
10541068 return String(v | 0).padStart(3, ' ');
10551069 }
10561070
1071+ // Update pixel info display for synced highlight from other panels
1072+ function updatePixelInfoForHighlight(px, py) {
1073+ if (px === null || py === null) {
1074+ pixelInfo.textContent = '';
1075+ return;
1076+ }
1077+
1078+ if (px >= 0 && px < cols && py >= 0 && py < rows) {
1079+ const idx = (py * cols + px) * channels;
1080+ let valStr = '';
1081+ if (channels === 1) {
1082+ valStr = formatValue(rawData[idx]);
1083+ } else if (channels === 4) {
1084+ valStr = \`R:\${formatValue(rawData[idx])} G:\${formatValue(rawData[idx+1])} B:\${formatValue(rawData[idx+2])} A:\${formatValue(rawData[idx+3])}\`;
1085+ } else {
1086+ valStr = \`R:\${formatValue(rawData[idx])} G:\${formatValue(rawData[idx+1])} B:\${formatValue(rawData[idx+2])}\`;
1087+ }
1088+ pixelInfo.textContent = \`(\${px}, \${py}) : \${valStr}\`;
1089+ } else {
1090+ pixelInfo.textContent = '';
1091+ }
1092+ }
1093+
10571094 function updateCanvasSize() {
10581095 const containerRect = container.getBoundingClientRect();
10591096 const dpr = window.devicePixelRatio || 1;
@@ -1285,12 +1322,37 @@ export function getWebviewContentForMat(
12851322 drawGrid();
12861323 drawPixelTextOverlay();
12871324
1325+ // Draw pixel highlight (blue border) for synchronized viewing
1326+ drawPixelHighlight();
1327+
12881328 // Update zoom level display
12891329 // Fixed-width zoom display: min 1 digit, max 5 digits, padded to 5 with spaces + 4 trailing spaces
12901330 const pct = Math.max(0, Math.round(scale * 100));
12911331 const pctStr = String(pct).slice(0, 5).padStart(5, ' ');
12921332 zoomLevelDisplay.textContent = pctStr + '% ';
12931333 }
1334+
1335+ // Draw pixel highlight with blue border (for synced panels)
1336+ function drawPixelHighlight() {
1337+ // Use either synced highlight or local hover
1338+ const px = highlightPixelX !== null ? highlightPixelX : localHoverPixelX;
1339+ const py = highlightPixelY !== null ? highlightPixelY : localHoverPixelY;
1340+
1341+ if (px === null || py === null) return;
1342+ if (px < 0 || px >= cols || py < 0 || py >= rows) return;
1343+
1344+ // Calculate screen position of the pixel
1345+ const screenX = offsetX + px * scale;
1346+ const screenY = offsetY + py * scale;
1347+ const pixelSize = scale;
1348+
1349+ // Draw blue border (2px thick)
1350+ ctx.save();
1351+ ctx.strokeStyle = '#00aaff';
1352+ ctx.lineWidth = 2;
1353+ ctx.strokeRect(screenX, screenY, pixelSize, pixelSize);
1354+ ctx.restore();
1355+ }
12941356
12951357 function requestRender() {
12961358 if (renderQueued) return;
@@ -1537,8 +1599,37 @@ export function getWebviewContentForMat(
15371599 valStr = \`R:\${formatValue(rawData[idx])} G:\${formatValue(rawData[idx+1])} B:\${formatValue(rawData[idx+2])}\`;
15381600 }
15391601 pixelInfo.textContent = \`(\${imgX}, \${imgY}) : \${valStr}\`;
1602+
1603+ // Update local hover pixel and send to sync
1604+ if (localHoverPixelX !== imgX || localHoverPixelY !== imgY) {
1605+ localHoverPixelX = imgX;
1606+ localHoverPixelY = imgY;
1607+ requestRender();
1608+ // Send pixel highlight to synced panels
1609+ if (!isShuttingDown && isInitialized) {
1610+ vscode.postMessage({
1611+ command: 'pixelHighlight',
1612+ pixelX: imgX,
1613+ pixelY: imgY
1614+ });
1615+ }
1616+ }
15401617 } else {
15411618 pixelInfo.textContent = '';
1619+ // Clear local hover
1620+ if (localHoverPixelX !== null || localHoverPixelY !== null) {
1621+ localHoverPixelX = null;
1622+ localHoverPixelY = null;
1623+ requestRender();
1624+ // Clear highlight on synced panels
1625+ if (!isShuttingDown && isInitialized) {
1626+ vscode.postMessage({
1627+ command: 'pixelHighlight',
1628+ pixelX: null,
1629+ pixelY: null
1630+ });
1631+ }
1632+ }
15421633 }
15431634 });
15441635
0 commit comments