* Cache a link for fast lookup
(link: ILink)
| 111 | * Cache a link for fast lookup |
| 112 | */ |
| 113 | private cacheLink(link: ILink): void { |
| 114 | // Try to get hyperlink_id for this link |
| 115 | const { start } = link.range; |
| 116 | const line = this.terminal.buffer.active.getLine(start.y); |
| 117 | if (line) { |
| 118 | const cell = line.getCell(start.x); |
| 119 | if (!cell) { |
| 120 | // Fallback: cache by position range |
| 121 | const { start: s, end: e } = link.range; |
| 122 | const cacheKey = `r${s.y}:${s.x}-${e.x}`; |
| 123 | this.linkCache.set(cacheKey, link); |
| 124 | return; |
| 125 | } |
| 126 | const hyperlinkId = cell.getHyperlinkId(); |
| 127 | |
| 128 | if (hyperlinkId > 0) { |
| 129 | // Cache by hyperlink_id (best case - stable across rows) |
| 130 | this.linkCache.set(`h${hyperlinkId}`, link); |
| 131 | return; |
| 132 | } |
| 133 | } |
| 134 | |
| 135 | // Fallback: cache by position range |
| 136 | // Format: r${row}:${startX}-${endX} |
| 137 | const { start: s, end: e } = link.range; |
| 138 | const cacheKey = `r${s.y}:${s.x}-${e.x}`; |
| 139 | this.linkCache.set(cacheKey, link); |
| 140 | } |
| 141 | |
| 142 | /** |
| 143 | * Check if a position is within a link's range |
no test coverage detected