fix(keymap-upgrader): Fix highlight on last line

Fixed an issue where a text edit at the very end of a file would cause
it to highlight from the start of the edit to the start of the file
instead of to the end of the file.
This commit is contained in:
Joel Spadin 2024-01-26 21:03:49 -06:00
parent c2299e2203
commit be75da096c

View File

@ -55,7 +55,11 @@ function getLineBreakPositions(text: string) {
}
function positionToLineNumber(position: number, lineBreaks: number[]) {
const line = lineBreaks.findIndex((lineBreak) => position <= lineBreak);
if (position >= lineBreaks[lineBreaks.length - 1]) {
return lineBreaks.length + 1;
}
const line = lineBreaks.findIndex((lineBreak) => position < lineBreak);
return line < 0 ? 0 : line + 1;
}