From ed4e02e96fa8f7582e088ecbc5b8ca428cf22cce Mon Sep 17 00:00:00 2001 From: bincxz <16399091+binaricat@users.noreply.github.com> Date: Fri, 31 Jul 2026 12:44:03 +0800 Subject: [PATCH] Handle wrap-pending cursor in row highlight --- .../runtime/cursorLineHighlight.test.ts | 18 ++++++++++++++++++ .../terminal/runtime/cursorLineHighlight.ts | 4 ++-- 2 files changed, 20 insertions(+), 2 deletions(-) diff --git a/components/terminal/runtime/cursorLineHighlight.test.ts b/components/terminal/runtime/cursorLineHighlight.test.ts index 29de874ee..2d4d7c826 100644 --- a/components/terminal/runtime/cursorLineHighlight.test.ts +++ b/components/terminal/runtime/cursorLineHighlight.test.ts @@ -274,6 +274,24 @@ test('CursorLineHighlighter leaves the cursor cell above the blank tail', () => highlighter.dispose(); }); +test('CursorLineHighlighter clamps a wrap-pending cursor to the last cell', () => { + const term = createFakeTerm(10); + term.setLineLength(4); + term.setCursorX(10); + const highlighter = new CursorLineHighlighter(term as never); + highlighter.setBackgroundColor('#263449'); + highlighter.setEnabled(true); + + assert.deepEqual( + term.decorations.map(({ options }) => ({ x: options.x, width: options.width })), + [ + { x: 0, width: 4 }, + { x: 4, width: 5 }, + ], + ); + highlighter.dispose(); +}); + test('CursorLineHighlighter leaves colored and inverse cells untouched', () => { const term = createFakeTerm(10); term.setColoredForegrounds([2, 3]); diff --git a/components/terminal/runtime/cursorLineHighlight.ts b/components/terminal/runtime/cursorLineHighlight.ts index ad26ccb53..2930e7b2e 100644 --- a/components/terminal/runtime/cursorLineHighlight.ts +++ b/components/terminal/runtime/cursorLineHighlight.ts @@ -217,8 +217,8 @@ export class CursorLineHighlighter implements IDisposable { private getTailRanges(contentEnd: number, cols: number, cursorX: number): HighlightRange[] { if (contentEnd >= cols) return []; - const cursorColumn = cursorX >= 0 && cursorX < cols ? cursorX : null; - if (cursorColumn === null || cursorColumn < contentEnd) { + const cursorColumn = Math.min(Math.max(cursorX, 0), cols - 1); + if (cursorColumn < contentEnd) { return [{ x: contentEnd, width: cols - contentEnd }]; } return [