diff --git a/src/test/unit/highlights/highlight_grid.test.ts b/src/test/unit/highlights/highlight_grid.test.ts index 30e1ed0f4..9497ffe48 100644 --- a/src/test/unit/highlights/highlight_grid.test.ts +++ b/src/test/unit/highlights/highlight_grid.test.ts @@ -630,6 +630,26 @@ describe("processHighlightCellsEvent", () => { }, ], }, + { + testName: "virtual highlights can exceed line length", + events: [ + { + row: 2, + vimCol: 6, + validCells: [{ hlId: 2, text: "!" }], + lineText: "hello", + tabSize: 4, + }, + ], + expectedRanges: [ + { + textType: "virtual" as const, + highlights: [{ hlId: 2, text: "!", virtText: "!" }], + line: 12, + col: 6, + }, + ], + }, ].forEach( ({ testName, diff --git a/src/utils/text.ts b/src/utils/text.ts index d90711dfc..b53a6a95e 100644 --- a/src/utils/text.ts +++ b/src/utils/text.ts @@ -24,6 +24,7 @@ export function calculateEditorColFromVimScreenCol(line: string, screenCol: numb if (screenCol === 0 || !line) { return 0; } + let currentCharIdx = 0; let currentVimCol = 0; while (currentVimCol < screenCol) {