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 129a8044fd
commit ebdc8d6435

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;
}