From b6244d4962e3a1f70ecf3ffbe69ad8a47941b71d Mon Sep 17 00:00:00 2001 From: Humza Shahid Date: Fri, 19 Sep 2025 04:03:54 +0100 Subject: [PATCH] amend motion to move to a line: if the requested line has a linebreak as the next character after it, stay at the current position, or else add 1 to the linebreak's idx so that we go to the first character of the line --- fcore/cursor.sml | 2 +- fcore/normal-mode/normal-move.sml | 11 ++++++++++- 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/fcore/cursor.sml b/fcore/cursor.sml index 4162301..f066475 100644 --- a/fcore/cursor.sml +++ b/fcore/cursor.sml @@ -1044,7 +1044,7 @@ struct * increment by 1 as we want to go to first char after line break *) bufferIdx + lineIdx else - bufferIdx + lineIdx + 1 + bufferIdx + lineIdx end end | (_, _) => diff --git a/fcore/normal-mode/normal-move.sml b/fcore/normal-mode/normal-move.sml index 7feacd8..db76d2c 100644 --- a/fcore/normal-mode/normal-move.sml +++ b/fcore/normal-mode/normal-move.sml @@ -129,8 +129,17 @@ struct (* get idx of first chr after linebreak *) val cursorIdx = Cursor.getLineStartIdx (buffer, reqLine) - val buffer = LineGap.goToIdx (cursorIdx, buffer) + + (* we got the line start idx, but we want to move to the index + * after it, where the first character of the line is. + * Unless the next character is a line break, + * in which case we want to stay at the current idx. *) + val cursorIdx = + if Cursor.isNextChrEndOfLine (buffer, cursorIdx) then cursorIdx + else cursorIdx + 1 + val buffer = LineGap.goToIdx (cursorIdx, buffer) + val visualScrollColumn = TextScroll.getScrollColumn (buffer, cursorIdx, windowWidth, prevScrollColumn)