don't deleteByDfa when buffer's length is 1, because that would mean that we would be deleting last newline in file

This commit is contained in:
2025-09-23 07:04:20 +01:00
parent 02ada5765b
commit 9174e4923c

View File

@@ -227,26 +227,30 @@ struct
finishAfterDeletingBuffer (app, low, buffer, time, initialMsg) finishAfterDeletingBuffer (app, low, buffer, time, initialMsg)
end end
fun deleteByDfa (app: app_type, count, fMove, time) = fun deleteByDfa (app as {buffer, ...}: app_type, count, fMove, time) =
let if #textLength buffer = 1 then
val {buffer, cursorIdx, ...} = app NormalFinish.clearMode app
else
let
val {buffer, cursorIdx, ...} = app
val buffer = LineGap.goToIdx (cursorIdx, buffer) val buffer = LineGap.goToIdx (cursorIdx, buffer)
val otherIdx = fMove (buffer, cursorIdx, count) val otherIdx = fMove (buffer, cursorIdx, count)
in in
if otherIdx > cursorIdx then if otherIdx > cursorIdx then
(* prevent us from deleting last newline if otherIdx >= #textLength buffer then
* to help us preserve unix-style line endings *) (* prevent us from deleting last newline
if otherIdx > #textLength buffer then * to help us preserve unix-style line endings *)
finishDeleteByDfa let val high = #textLength buffer - 1
(app, cursorIdx, #textLength buffer - 1, buffer, time) in finishDeleteByDfa (app, cursorIdx, high, buffer, time)
end
else
finishDeleteByDfa (app, cursorIdx, otherIdx, buffer, time)
else if otherIdx < cursorIdx then
finishDeleteByDfa (app, otherIdx, cursorIdx, buffer, time)
else else
finishDeleteByDfa (app, cursorIdx, otherIdx, buffer, time) NormalFinish.clearMode app
else if otherIdx < cursorIdx then end
finishDeleteByDfa (app, otherIdx, cursorIdx, buffer, time)
else
NormalFinish.clearMode app
end
fun deleteCharsLeft (app: app_type, count, time) = fun deleteCharsLeft (app: app_type, count, time) =
let let