Skip to content

Commit 2ad3923

Browse files
committed
move the original name to an inline tooltip
1 parent e522bad commit 2ad3923

File tree

1 file changed

+33
-6
lines changed

1 file changed

+33
-6
lines changed

code.js

Lines changed: 33 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1154,6 +1154,7 @@
11541154
const badMappingBatches = [];
11551155
const whitespaceBatch = [];
11561156
const textBatch = [];
1157+
let hoveredName = null;
11571158
for (let i = 0; i < originalLineColors.length; i++) {
11581159
mappingBatches.push([]);
11591160
badMappingBatches.push([]);
@@ -1204,6 +1205,9 @@
12041205
// Get the bounds of this mapping, which may be empty if it's ignored
12051206
const range = rangeOfMapping(map);
12061207
if (range === null) continue;
1208+
const { startColumn, endColumn } = range;
1209+
const color = mappings[map + 3] % originalLineColors.length;
1210+
const [x1, y1, x2, y2] = boxForRange(x, y, row, columnWidth, range);
12071211

12081212
// Check if this mapping is hovered
12091213
let isHovered = false;
@@ -1226,12 +1230,16 @@
12261230
// mapping instead of showing everything that matches the target
12271231
// so hovering isn't confusing.
12281232
: isGenerated ? matchesGenerated : matchesOriginal);
1233+
if (isGenerated && matchesGenerated && hoveredMapping.originalName !== -1) {
1234+
hoveredName = {
1235+
text: originalName(hoveredMapping.originalName),
1236+
x: Math.round(x - scrollX + margin + textPaddingX + range.startColumn * columnWidth - 2),
1237+
y: Math.round(y + textPaddingY - scrollY + (row + 1.2) * rowHeight),
1238+
};
1239+
}
12291240
}
12301241

12311242
// Add a rectangle to that color's batch
1232-
const { startColumn, endColumn } = range;
1233-
const color = mappings[map + 3] % originalLineColors.length;
1234-
const [x1, y1, x2, y2] = boxForRange(x, y, row, columnWidth, range);
12351243
if (isHovered) {
12361244
hoverBoxes.push({ color, rect: [x1 - 2, y1 - 2, x2 - x1 + 4, y2 - y1 + 4] });
12371245
} else if (row >= lines.length || startColumn > endOfLineColumn) {
@@ -1314,9 +1322,6 @@
13141322
if (hoveredMapping && hoveredMapping.originalColumn !== -1) {
13151323
if (sourceIndex === null) {
13161324
status = `Line ${hoveredMapping.generatedLine + 1}, Offset ${hoveredMapping.generatedColumn}`;
1317-
if (hoveredMapping.originalName !== -1) {
1318-
status += `, Name ${originalName(hoveredMapping.originalName)}`;
1319-
}
13201325
} else {
13211326
status = `Line ${hoveredMapping.originalLine + 1}, Offset ${hoveredMapping.originalColumn}`;
13221327
if (hoveredMapping.originalSource !== sourceIndex) {
@@ -1342,6 +1347,28 @@
13421347
}
13431348
}
13441349

1350+
// Draw the original name tooltip
1351+
if (hoveredName) {
1352+
const { text, x, y } = hoveredName;
1353+
const w = 2 * textPaddingX + c.measureText(text).width;
1354+
const h = rowHeight;
1355+
const r = 4;
1356+
c.beginPath();
1357+
c.arc(x + r, y + r, r, - Math.PI, -Math.PI / 2, false);
1358+
c.arc(x + w - r, y + r, r, -Math.PI / 2, 0, false);
1359+
c.arc(x + w - r, y + h - r, r, 0, Math.PI / 2, false);
1360+
c.arc(x + r, y + h - r, r, Math.PI / 2, Math.PI, false);
1361+
c.save();
1362+
c.shadowColor = 'rgba(0, 0, 0, 0.5)';
1363+
c.shadowOffsetY = 3;
1364+
c.shadowBlur = 10;
1365+
c.fillStyle = textColor;
1366+
c.fill();
1367+
c.restore();
1368+
c.fillStyle = backgroundColor;
1369+
c.fillText(text, x + textPaddingX, y + 0.7 * rowHeight);
1370+
}
1371+
13451372
// Draw the margin shadow
13461373
if (scrollX > 0) {
13471374
let gradient = c.createLinearGradient(x + margin, 0, x + margin + shadowWidth, 0);

0 commit comments

Comments
 (0)