when deleting using a DFA motion, make sure we have a linebreak at the end so that we still have unix-style line endings as an invariant

This commit is contained in:
2025-09-22 12:41:33 +01:00
parent 351f7e9bf9
commit e3148e6ac1

View File

@@ -217,18 +217,37 @@ struct
in helpDelete (app, buffer, cursorIdx, cursorIdx, count, fMove, time) in helpDelete (app, buffer, cursorIdx, cursorIdx, count, fMove, time)
end end
fun finishDeleteByDfa (app, low, high, buffer, time) =
let
val length = high - low
val buffer = LineGap.goToIdx (high, buffer)
val initialMsg = Fn.initMsgs (low, length, buffer)
val buffer = LineGap.delete (low, length, buffer)
in
finishAfterDeletingBuffer (app, low, buffer, time, initialMsg)
end
fun deleteByDfa (app: app_type, count, fMove, time) = fun deleteByDfa (app: app_type, count, fMove, time) =
let let
val {buffer, cursorIdx, ...} = app 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)
val low = Int.min (cursorIdx, otherIdx)
val high = Int.max (cursorIdx, otherIdx)
val length = high - low
in in
deleteAndFinish (app, low, length, buffer, time) if otherIdx > cursorIdx then
let
val buffer =
if otherIdx > #textLength buffer - 1 then
LineGap.append ("\n\n", buffer)
else
buffer
in
finishDeleteByDfa (app, cursorIdx, otherIdx, buffer, time)
end
else if otherIdx < cursorIdx then
finishDeleteByDfa (app, otherIdx, cursorIdx, buffer, time)
else
NormalFinish.clearMode app
end end
fun deleteCharsLeft (app: app_type, count, time) = fun deleteCharsLeft (app: app_type, count, time) =