handle edge case when deleting by DFA: when we are deleting to the end of the file and if cursor is on first character after newline, then we also want to delete preceding newline too. Or else we will end up with two newlines at the end of the file, which is not what we want.

This commit is contained in:
2025-09-23 07:18:58 +01:00
parent ec10f3e025
commit 0b0d5268fc

View File

@@ -241,8 +241,17 @@ struct
if otherIdx >= #textLength buffer then if otherIdx >= #textLength buffer then
(* prevent us from deleting last newline (* prevent us from deleting last newline
* to help us preserve unix-style line endings *) * to help us preserve unix-style line endings *)
let val high = #textLength buffer - 1 let
in finishDeleteByDfa (app, cursorIdx, high, buffer, time) (* if we're on the first character/column in a line,
* we would like to delete the preceding newline too *)
val cursorIdx =
if Cursor.isPrevChrStartOfLine (buffer, cursorIdx) then
cursorIdx - 1
else
cursorIdx
val high = #textLength buffer - 1
in
finishDeleteByDfa (app, cursorIdx, high, buffer, time)
end end
else else
finishDeleteByDfa (app, cursorIdx, otherIdx, buffer, time) finishDeleteByDfa (app, cursorIdx, otherIdx, buffer, time)