fix the last MakeNormalDelete.deleteLine bug: if we delete such that the startIdx (prior to deletion) becomes longer than the text in the buffer, we move the cursor to the start of the last line

This commit is contained in:
2025-09-16 07:01:55 +01:00
parent 6507b9d49c
commit 70ffea21b3

View File

@@ -275,13 +275,31 @@ struct
let let
val {buffer, cursorIdx, searchString, ...} = app val {buffer, cursorIdx, searchString, ...} = app
val buffer = LineGap.goToIdx (cursorIdx, buffer) val buffer = LineGap.goToIdx (cursorIdx, buffer)
val textLength = #textLength buffer
val startIdx = Cursor.vi0 (buffer, cursorIdx) val startIdx = Cursor.vi0 (buffer, cursorIdx)
val finishIdx = Cursor.viDlr (buffer, cursorIdx, count) + 2 val finishIdx = Cursor.viDlr (buffer, cursorIdx, count) + 2
val length = finishIdx - startIdx val length = finishIdx - startIdx
val buffer = LineGap.goToIdx (startIdx, buffer)
val initialMsg = Fn.initMsgs (startIdx, length, buffer)
val buffer = LineGap.delete (startIdx, length, buffer)
val textLength = #textLength buffer
in in
deleteAndFinish (app, startIdx, length, buffer, time) if startIdx >= textLength - 2 andalso textLength > 2 then
(* after deletion, we may have deleted the position
* that the cursor was previously on.
* If so, then we have to move the cursor backwards
* to the start of the previous line. *)
let
val tempIdx = textLength - 2
val buffer = LineGap.goToIdx (tempIdx, buffer)
val startIdx = Cursor.vi0 (buffer, tempIdx)
in
finishAfterDeletingBuffer (app, startIdx, buffer, time, initialMsg)
end
else
finishAfterDeletingBuffer (app, startIdx, buffer, time, initialMsg)
end end
fun helpDeleteLineBack (app, buffer, low, high, count, time) = fun helpDeleteLineBack (app, buffer, low, high, count, time) =