The best way to control Claude Code, Codex and more from any computer or phone
fix(web): keep wide characters in terminal links (#24013)
Co-authored-by: GPT-6.1 Sol <noreply@openai.com> Co-authored-by: maria-rcks <maria@kuuro.net>
Victor Vogel committed
Oct 29, 2026 at 12:52 UTC
d15233544ecfa8c746e5a3d0b7e7c3a08532fc74
3 files changed
+57
-5
apps/web/src/terminal/ghostty/core.ts
+2
-1
@@ -1067,7 +1067,8 @@ export class GhosttyTerminalCore {
1067
}
1068
}
1069
let wide = 0;
1070
- if (text.length === 0 && cells.at(-1)?.text.length) {
1070
+ // A wrap spacer in the final column can follow a spacer tail.
1071
+ if (text.length === 0 && (cells.at(-1)?.text.length || cells.length === cols - 1)) {
1072
this.assertSuccess(
1073
"ghostty_render_state_row_cells_get(raw)",
1074
this.runtime.call(
apps/web/src/terminal/ghostty/surface.test.ts
+36
@@ -512,6 +512,42 @@ const cell = (text: string): GhosttyCell => ({
512
});
513
514
describe("terminalLinkAtPositionWithRange", () => {
515
+ it.each([
516
+ { text: "https://example.com/日本", cols: 80, end: { x: 23, y: 0 } },
517
+ { text: "src/日本/main.ts:3:1", cols: 80, end: { x: 19, y: 0 } },
518
+ { text: "https://example.com/🙂", cols: 80, end: { x: 21, y: 0 } },
519
+ { text: "https://example.com/日本", cols: 23, end: { x: 1, y: 1 } },
520
+ ])("keeps every cell of $text clickable at $cols columns", async ({ text, cols, end }) => {
521
+ const core = await GhosttyTerminalCore.create(
522
+ cols,
523
+ 3,
524
+ 8,
525
+ 16,
526
+ {
527
+ foreground: { r: 255, g: 255, b: 255 },
528
+ background: { r: 0, g: 0, b: 0 },
529
+ cursor: { r: 255, g: 255, b: 255 },
530
+ },
531
+ () => {},
532
+ );
533
+ try {
534
+ core.write(text + " next");
535
+ const rows = core.snapshot().rowData;
536
+ for (let y = 0; y <= end.y; y += 1) {
537
+ const lastColumn = y === end.y ? end.x : cols - 2;
538
+ for (let x = 0; x <= lastColumn; x += 1) {
539
+ expect(terminalLinkAtPositionWithRange(rows, y, x)).toEqual({
540
+ text,
541
+ range: { start: { x: 0, y: 0 }, end },
542
+ });
543
+ }
544
+ }
545
+ expect(terminalLinkAtPositionWithRange(rows, end.y, end.x + 1)).toBeNull();
546
+ } finally {
547
+ core.dispose();
548
+ }
549
+ });
550
+
551
it("activates a wrapped quoted Windows path from its spaces and position suffix", () => {
552
const row = (text: string, isWrapContinuation: boolean): GhosttyRow => ({
553
cells: Array.from(text, (character) => cell(character)),
apps/web/src/terminal/ghostty/surface.ts
+19
-4
@@ -2,7 +2,9 @@ import { isMacPlatform } from "../../lib/utils";
2
import { SELECTION_MULTI_CLICK_INTERVAL_MS } from "../../lib/selectionActions";
3
import { collectWrappedTerminalLinkLine, extractTerminalLinks } from "../../terminal-links";
4
import {
5
+ GHOSTTY_CELL_WIDE,
6
GhosttyTerminalCore,
7
+ type GhosttyCell,
8
type GhosttyScrollbar,
9
type GhosttySnapshot,
10
type GhosttyTheme,
@@ -201,15 +203,23 @@ function terminalGridCellAt(options: {
203
};
204
}
205
206
+function terminalCellText(cell: GhosttyCell): string {
207
+ if (cell.wide === GHOSTTY_CELL_WIDE.spacerTail || cell.wide === GHOSTTY_CELL_WIDE.spacerHead) {
208
+ return "";
209
+ }
210
+ return cell.text || " ";
211
+}
212
+
213
function terminalRowText(row: GhosttySnapshot["rowData"][number], trimRight: boolean): string {
205
- const text = row.cells.map((cell) => cell.text || " ").join("");
214
+ const text = row.cells.map(terminalCellText).join("");
215
return trimRight ? text.trimEnd() : text;
216
}
217
218
function terminalColumnOffset(row: GhosttySnapshot["rowData"][number], column: number): number {
219
let offset = 0;
220
for (let cellIndex = 0; cellIndex < column; cellIndex += 1) {
212
- offset += row.cells[cellIndex]?.text.length || 1;
221
+ const cell = row.cells[cellIndex];
222
+ offset += cell ? terminalCellText(cell).length : 1;
223
}
224
return offset;
225
}
@@ -265,7 +275,8 @@ export function terminalLinkAtPositionWithRange(
275
const lastSegment = wrappedLine.segments.at(-1);
276
const lastRow = lastSegment ? rows[lastSegment.bufferLineNumber - 1] : undefined;
277
const continuesBelowViewport = lastRow !== undefined && lastRow.wrapsToNext;
268
- const offset = segment.startIndex + terminalColumnOffset(row, column);
278
+ const hitColumn = row.cells[column]?.wide === GHOSTTY_CELL_WIDE.spacerTail ? column - 1 : column;
279
+ const offset = segment.startIndex + terminalColumnOffset(row, hitColumn);
280
for (const match of extractTerminalLinks(wrappedLine.text)) {
281
if (offset >= match.start && offset < match.end) {
282
if (match.end === wrappedLine.text.length && continuesBelowViewport) return null;
@@ -278,6 +289,7 @@ export function terminalLinkAtPositionWithRange(
289
const startRow = startSegment ? rows[startSegment.bufferLineNumber - 1] : undefined;
290
const endRow = endSegment ? rows[endSegment.bufferLineNumber - 1] : undefined;
291
if (!startSegment || !endSegment || !startRow || !endRow) return null;
292
+ const endColumn = terminalColumnAtOffset(endRow, match.end - 1 - endSegment.startIndex);
293
return {
294
text: match.text,
295
range: {
@@ -286,7 +298,10 @@ export function terminalLinkAtPositionWithRange(
298
y: startSegment.bufferLineNumber - 1,
299
},
300
end: {
289
- x: terminalColumnAtOffset(endRow, match.end - 1 - endSegment.startIndex),
301
+ x:
302
+ endRow.cells[endColumn + 1]?.wide === GHOSTTY_CELL_WIDE.spacerTail
303
+ ? endColumn + 1
304
+ : endColumn,
305
y: endSegment.bufferLineNumber - 1,
306
},
307
},