|
1154 | 1154 | const badMappingBatches = []; |
1155 | 1155 | const whitespaceBatch = []; |
1156 | 1156 | const textBatch = []; |
| 1157 | + let hoveredName = null; |
1157 | 1158 | for (let i = 0; i < originalLineColors.length; i++) { |
1158 | 1159 | mappingBatches.push([]); |
1159 | 1160 | badMappingBatches.push([]); |
|
1204 | 1205 | // Get the bounds of this mapping, which may be empty if it's ignored |
1205 | 1206 | const range = rangeOfMapping(map); |
1206 | 1207 | 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); |
1207 | 1211 |
|
1208 | 1212 | // Check if this mapping is hovered |
1209 | 1213 | let isHovered = false; |
|
1226 | 1230 | // mapping instead of showing everything that matches the target |
1227 | 1231 | // so hovering isn't confusing. |
1228 | 1232 | : 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 | + } |
1229 | 1240 | } |
1230 | 1241 |
|
1231 | 1242 | // 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); |
1235 | 1243 | if (isHovered) { |
1236 | 1244 | hoverBoxes.push({ color, rect: [x1 - 2, y1 - 2, x2 - x1 + 4, y2 - y1 + 4] }); |
1237 | 1245 | } else if (row >= lines.length || startColumn > endOfLineColumn) { |
|
1314 | 1322 | if (hoveredMapping && hoveredMapping.originalColumn !== -1) { |
1315 | 1323 | if (sourceIndex === null) { |
1316 | 1324 | status = `Line ${hoveredMapping.generatedLine + 1}, Offset ${hoveredMapping.generatedColumn}`; |
1317 | | - if (hoveredMapping.originalName !== -1) { |
1318 | | - status += `, Name ${originalName(hoveredMapping.originalName)}`; |
1319 | | - } |
1320 | 1325 | } else { |
1321 | 1326 | status = `Line ${hoveredMapping.originalLine + 1}, Offset ${hoveredMapping.originalColumn}`; |
1322 | 1327 | if (hoveredMapping.originalSource !== sourceIndex) { |
|
1342 | 1347 | } |
1343 | 1348 | } |
1344 | 1349 |
|
| 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 | + |
1345 | 1372 | // Draw the margin shadow |
1346 | 1373 | if (scrollX > 0) { |
1347 | 1374 | let gradient = c.createLinearGradient(x + margin, 0, x + margin + shadowWidth, 0); |
|
0 commit comments