fix minor bug regarding 'NormalMove.moveCursorDown': after a <count-j> that moved the cursor to the last line in the buffer, the cursor would be at the last column too, even if that wasn't the previous column. To address this issue, we take out code that calculates the lineIdx from the 'NormalMove.finishMoveCursorUpDown' function, and have both 'NormalMove.moveCursorUp' and 'NormalMove.moveCursorDown' calculate their own lineIdx in different ways and pass it to the 'NormalMove.finishMoveCursorUpAndDown' function.

This commit is contained in:
2025-09-20 02:58:51 +01:00
parent 090e7ccea2
commit c29afbdb7c

View File

@@ -108,7 +108,7 @@ struct
end end
fun finishMoveCursorUpDown fun finishMoveCursorUpDown
(app: app_type, newCursorLineNumber, buffer, column) = (app: app_type, newCursorLineNumber, buffer, column, lineIdx) =
let let
val val
{ windowWidth { windowWidth
@@ -121,13 +121,6 @@ struct
, ... , ...
} = app } = app
val buffer = LineGap.goToLine (newCursorLineNumber, buffer)
val lineIdx = LineGap.lineNumberToIdx (newCursorLineNumber, buffer)
val buffer = LineGap.goToIdx (lineIdx, buffer)
val lineIdx =
if Cursor.isNextChrEndOfLine (buffer, lineIdx) then lineIdx
else lineIdx + 1
val buffer = LineGap.goToIdx (lineIdx, buffer) val buffer = LineGap.goToIdx (lineIdx, buffer)
val endOfLineIdx = Cursor.viDlr (buffer, lineIdx, 1) val endOfLineIdx = Cursor.viDlr (buffer, lineIdx, 1)
val endOfLineIdx = val endOfLineIdx =
@@ -200,8 +193,15 @@ struct
LineGap.idxToLineNumber (cursorIdx, buffer) LineGap.idxToLineNumber (cursorIdx, buffer)
val newCursorLineNumber = Int.max (cursorLineNumber - count, 0) val newCursorLineNumber = Int.max (cursorLineNumber - count, 0)
val column = if newCursorLineNumber = 0 then column - 1 else column val column = if newCursorLineNumber = 0 then column - 1 else column
val buffer = LineGap.goToLine (newCursorLineNumber, buffer)
val lineIdx = LineGap.lineNumberToIdx (newCursorLineNumber, buffer)
val buffer = LineGap.goToIdx (lineIdx, buffer)
val lineIdx =
if Cursor.isNextChrEndOfLine (buffer, lineIdx) then lineIdx
else lineIdx + 1
in in
finishMoveCursorUpDown (app, newCursorLineNumber, buffer, column) finishMoveCursorUpDown (app, newCursorLineNumber, buffer, column, lineIdx)
end end
fun moveCursorDown (app: app_type, count) = fun moveCursorDown (app: app_type, count) =
@@ -236,8 +236,22 @@ struct
Int.max (0, #lineLength buffer - 1) Int.max (0, #lineLength buffer - 1)
else else
newCursorLineNumber newCursorLineNumber
val buffer = LineGap.goToLine (newCursorLineNumber, buffer)
val lineIdx = LineGap.lineNumberToIdx (newCursorLineNumber, buffer)
val buffer = LineGap.goToIdx (lineIdx, buffer)
val lineIdx =
if lineIdx >= #textLength buffer - 2 then
Int.max (0, #textLength buffer - 2)
else
lineIdx
val lineIdx =
if Cursor.isNextChrEndOfLine (buffer, lineIdx) then lineIdx
else lineIdx + 1
val buffer = LineGap.goToIdx (lineIdx, buffer)
val lineIdx = Cursor.vi0 (buffer, lineIdx)
in in
finishMoveCursorUpDown (app, newCursorLineNumber, buffer, column) finishMoveCursorUpDown (app, newCursorLineNumber, buffer, column, lineIdx)
end end
fun moveToLine (app: app_type, reqLine) = fun moveToLine (app: app_type, reqLine) =