From 0b0d5268fc96de5fce7f565f096fd9720df87e9d Mon Sep 17 00:00:00 2001 From: Humza Shahid Date: Tue, 23 Sep 2025 07:18:58 +0100 Subject: [PATCH] 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. --- fcore/normal-mode/make-normal-delete.sml | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/fcore/normal-mode/make-normal-delete.sml b/fcore/normal-mode/make-normal-delete.sml index 4a8b868..c705397 100644 --- a/fcore/normal-mode/make-normal-delete.sml +++ b/fcore/normal-mode/make-normal-delete.sml @@ -241,8 +241,17 @@ struct if otherIdx >= #textLength buffer then (* prevent us from deleting last newline * to help us preserve unix-style line endings *) - let val high = #textLength buffer - 1 - in finishDeleteByDfa (app, cursorIdx, high, buffer, time) + let + (* 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 else finishDeleteByDfa (app, cursorIdx, otherIdx, buffer, time)