From 9a15b1715a2956af133fc5f9268f07b7390f548e Mon Sep 17 00:00:00 2001 From: Humza Shahid Date: Tue, 23 Sep 2025 15:30:28 +0100 Subject: [PATCH] pass all tests for 'j' motion --- fcore/normal-mode/normal-move.sml | 13 ++++++------- test/normal-move.sml | 2 +- 2 files changed, 7 insertions(+), 8 deletions(-) diff --git a/fcore/normal-mode/normal-move.sml b/fcore/normal-mode/normal-move.sml index e26b6c6..c53ffe1 100644 --- a/fcore/normal-mode/normal-move.sml +++ b/fcore/normal-mode/normal-move.sml @@ -277,11 +277,16 @@ struct val lineIdx = LineGap.lineNumberToIdx (newCursorLineNumber, buffer) val buffer = LineGap.goToIdx (lineIdx, buffer) in - if lineIdx >= #textLength buffer then + if lineIdx >= #textLength buffer - 1 then (* we reached last line *) let val lineIdx = Int.max (#textLength buffer - 1, 0) val buffer = LineGap.goToIdx (lineIdx, buffer) + + val lineIdx = + if Cursor.isOnNewlineAfterChr (buffer, lineIdx) then lineIdx - 1 + else lineIdx + val startOfLine = Cursor.vi0 (buffer, lineIdx) in if cursorIdx >= startOfLine then @@ -292,12 +297,6 @@ struct finishMoveCursorUpDown (app, newCursorLineNumber, buffer, column, startOfLine) end - else if lineIdx = #textLength buffer - 1 then - (* last line in buffer ends with \n - * and we just reached it *) - let val () = print "296\n" - in raise Fail "" - end else let val lineIdx = diff --git a/test/normal-move.sml b/test/normal-move.sml index 9445f1a..ec2055d 100644 --- a/test/normal-move.sml +++ b/test/normal-move.sml @@ -463,7 +463,7 @@ struct val {cursorIdx, ...} = TestUtils.updateMany (app, "2j") (* assert *) - val expectedIdx = initialCursorIdx + val expectedIdx = 6 in Expect.isTrue (cursorIdx = expectedIdx) end)