From e3148e6ac1362f2351fcb575a41b1342b3f3efaf Mon Sep 17 00:00:00 2001 From: Humza Shahid Date: Mon, 22 Sep 2025 12:41:33 +0100 Subject: [PATCH] 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 --- fcore/normal-mode/make-normal-delete.sml | 29 ++++++++++++++++++++---- 1 file changed, 24 insertions(+), 5 deletions(-) diff --git a/fcore/normal-mode/make-normal-delete.sml b/fcore/normal-mode/make-normal-delete.sml index 821b174..73f066d 100644 --- a/fcore/normal-mode/make-normal-delete.sml +++ b/fcore/normal-mode/make-normal-delete.sml @@ -217,18 +217,37 @@ struct in helpDelete (app, buffer, cursorIdx, cursorIdx, count, fMove, time) 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) = let val {buffer, cursorIdx, ...} = app val buffer = LineGap.goToIdx (cursorIdx, buffer) val otherIdx = fMove (buffer, cursorIdx, count) - - val low = Int.min (cursorIdx, otherIdx) - val high = Int.max (cursorIdx, otherIdx) - val length = high - low 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 fun deleteCharsLeft (app: app_type, count, time) =