Skip to content

Commit

Permalink
fix: inccommand highlights can exceed line length
Browse files Browse the repository at this point in the history
  • Loading branch information
ollien committed May 19, 2024
1 parent 479638f commit ef8d261
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 2 deletions.
24 changes: 24 additions & 0 deletions src/test/unit/highlights/highlight_grid.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -630,6 +630,30 @@ describe("processHighlightCellsEvent", () => {
},
],
},
{
testName: "virtual highlights can exceed line length",
events: [
{
row: 2,
vimCol: 6,
validCells: [

Check failure on line 639 in src/test/unit/highlights/highlight_grid.test.ts

View workflow job for this annotation

GitHub Actions / Lint

Replace `⏎························{·hlId:·2,·text:·"!"·},⏎····················` with `{·hlId:·2,·text:·"!"·}`
{ hlId: 2, text: "!" },
],
lineText: "hello",
tabSize: 4,
},
],
expectedRanges: [
{
textType: "virtual" as const,
highlights: [

Check failure on line 649 in src/test/unit/highlights/highlight_grid.test.ts

View workflow job for this annotation

GitHub Actions / Lint

Replace `⏎························{·hlId:·2,·text:·"!",·virtText:·"!"·},⏎····················` with `{·hlId:·2,·text:·"!",·virtText:·"!"·}`
{ hlId: 2, text: "!", virtText: "!" },
],
line: 12,
col: 6,
},
],

Check failure on line 655 in src/test/unit/highlights/highlight_grid.test.ts

View workflow job for this annotation

GitHub Actions / Lint

Insert `·`
},
].forEach(
({
testName,
Expand Down
5 changes: 3 additions & 2 deletions src/utils/text.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ export function calculateEditorColFromVimScreenCol(line: string, screenCol: numb
if (screenCol === 0 || !line) {
return 0;
}

let currentCharIdx = 0;
let currentVimCol = 0;
while (currentVimCol < screenCol) {
Expand All @@ -32,8 +33,8 @@ export function calculateEditorColFromVimScreenCol(line: string, screenCol: numb
currentCharIdx++;
}

if (currentCharIdx >= line.length) {
return currentCharIdx;
if (currentCharIdx >= wcswidth(line)) {
return currentCharIdx + (screenCol - currentVimCol);
}
}
return currentCharIdx;
Expand Down

0 comments on commit ef8d261

Please sign in to comment.