MCPcopy Create free account
hub / github.com/coder/ghostty-web / cacheLink

Method cacheLink

lib/link-detector.ts:113–140  ·  view source on GitHub ↗

* Cache a link for fast lookup

(link: ILink)

Source from the content-addressed store, hash-verified

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

Callers 1

scanRowMethod · 0.95

Calls 3

getLineMethod · 0.65
getCellMethod · 0.65
getHyperlinkIdMethod · 0.65

Tested by

no test coverage detected