From be75da096c86d87e414f4089cc27184dc0c6f5bf Mon Sep 17 00:00:00 2001 From: Joel Spadin <joelspadin@gmail.com> Date: Fri, 26 Jan 2024 21:03:49 -0600 Subject: [PATCH] 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. --- docs/src/keymap-upgrade/index.ts | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/docs/src/keymap-upgrade/index.ts b/docs/src/keymap-upgrade/index.ts index c46cbe07..0cd34807 100644 --- a/docs/src/keymap-upgrade/index.ts +++ b/docs/src/keymap-upgrade/index.ts @@ -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; }