Skip to content

Commit

Permalink
fix(highlight): fix eol highlight not displaying
Browse files Browse the repository at this point in the history
  • Loading branch information
xiyaowong committed May 19, 2024
1 parent 479638f commit 19d97b6
Showing 1 changed file with 15 additions and 1 deletion.
16 changes: 15 additions & 1 deletion src/utils/text.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,9 @@ export function expandTabs(line: string, tabWidth: number): string {
return expanded;
}

/**
* Note: This function is for use by the highlight module only.
*/
export function calculateEditorColFromVimScreenCol(line: string, screenCol: number, tabSize: number): number {
if (screenCol === 0 || !line) {
return 0;
Expand All @@ -33,7 +36,18 @@ export function calculateEditorColFromVimScreenCol(line: string, screenCol: numb
}

if (currentCharIdx >= line.length) {
return currentCharIdx;
// The basic logic of highlighting is to store them according
// to the editor column. For EOL highlights, the end-of-line position
// is always used as the decoration position, use CSS
// position offset for display.

// Typically, the starting vim column in the grid_line event only exceeds the
// line text length when there are EOL highlights, so the offset
// needs to be added directly here. Otherwise, the parts exceeding the
// line text length will use the same editor column, causing EOL highlights
// to be incorrectly covered.
const eolCol = Math.min(screenCol - currentVimCol, 0);
return currentCharIdx + eolCol;
}
}
return currentCharIdx;
Expand Down

0 comments on commit 19d97b6

Please sign in to comment.