progress reimplementing 'j' motion to pass new tests

This commit is contained in:
2025-09-23 15:22:49 +01:00
parent c3ca8dddf4
commit 95a4f109bd
3 changed files with 64 additions and 19 deletions

View File

@@ -275,21 +275,45 @@ struct
val buffer = LineGap.goToLine (newCursorLineNumber, buffer)
val lineIdx = LineGap.lineNumberToIdx (newCursorLineNumber, buffer)
val buffer = LineGap.goToIdx (lineIdx, buffer)
val lineIdx =
if Cursor.isPrevChrStartOfLine (buffer, lineIdx) then lineIdx
else lineIdx + 1
val lineIdx =
if lineIdx >= #textLength buffer - 1 then
Int.max (0, #textLength buffer - 1)
else
lineIdx
in
finishMoveCursorUpDown
(app, newCursorLineNumber, buffer, column, lineIdx)
if lineIdx >= #textLength buffer then
(* we reached last line *)
let
val lineIdx = Int.max (#textLength buffer - 1, 0)
val buffer = LineGap.goToIdx (lineIdx, buffer)
val startOfLine = Cursor.vi0 (buffer, lineIdx)
in
if cursorIdx >= startOfLine then
(* we are already on last line so don't move *)
NormalFinish.buildTextAndClear
(app, buffer, cursorIdx, searchList, [], bufferModifyTime)
else
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 =
if lineIdx >= #textLength buffer - 2 then
Int.max (0, #textLength buffer - 2)
else
lineIdx
val buffer = LineGap.goToIdx (lineIdx, buffer)
val lineIdx =
if Cursor.isOnNewlineAfterChr (buffer, lineIdx) then lineIdx + 1
else lineIdx
in
finishMoveCursorUpDown
(app, newCursorLineNumber, buffer, column, lineIdx)
end
end
end