From 3d9bf962e70923cf4492f98f8a9d59d80f5a9255 Mon Sep 17 00:00:00 2001 From: Humza Shahid Date: Tue, 16 Sep 2025 07:40:58 +0100 Subject: [PATCH] handle additional deleteLine edge case --- fcore/normal-mode/make-normal-delete.sml | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/fcore/normal-mode/make-normal-delete.sml b/fcore/normal-mode/make-normal-delete.sml index 4f479a4..4a532ac 100644 --- a/fcore/normal-mode/make-normal-delete.sml +++ b/fcore/normal-mode/make-normal-delete.sml @@ -277,6 +277,9 @@ struct val buffer = LineGap.goToIdx (cursorIdx, buffer) val startIdx = Cursor.vi0 (buffer, cursorIdx) + val buffer = LineGap.goToIdx (startIdx, buffer) + val isPrevChrStartOfLine = Cursor.isPrevChrStartOfLine (buffer, startIdx) + val finishIdx = Cursor.viDlr (buffer, cursorIdx, count) + 2 val length = finishIdx - startIdx @@ -296,7 +299,20 @@ struct val buffer = LineGap.goToIdx (tempIdx, buffer) val startIdx = Cursor.vi0 (buffer, tempIdx) in - finishAfterDeletingBuffer (app, startIdx, buffer, time, initialMsg) + if isPrevChrStartOfLine andalso startIdx = #textLength buffer - 2 then + (* We also have to handle the edge case where we delete below a + * linebreak, such that the linebreak is now at the end of the file. + * We have to handle this case because the last file-ending linebreak + * is not selectable, and we don't want the user to move the cursor + * to the first character of a \n\n pair. *) + let + val buffer = LineGap.append ("\n", buffer) + in + finishAfterDeletingBuffer + (app, startIdx + 1, buffer, time, initialMsg) + end + else + finishAfterDeletingBuffer (app, startIdx, buffer, time, initialMsg) end else finishAfterDeletingBuffer (app, startIdx, buffer, time, initialMsg)