From 351f7e9bf91e8cd1d7c623a5b00c19510bc4022b Mon Sep 17 00:00:00 2001 From: Humza Shahid Date: Mon, 22 Sep 2025 12:28:08 +0100 Subject: [PATCH] fix edge case with 'd$' motion: if deleting to end of file, we need to append two newlines --- fcore/normal-mode/make-normal-delete.sml | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/fcore/normal-mode/make-normal-delete.sml b/fcore/normal-mode/make-normal-delete.sml index 0cb6f7c..821b174 100644 --- a/fcore/normal-mode/make-normal-delete.sml +++ b/fcore/normal-mode/make-normal-delete.sml @@ -272,6 +272,7 @@ struct fun deleteToEndOfLine (app: app_type, time) = let val {buffer, cursorIdx, ...} = app + val buffer = LineGap.goToIdx (cursorIdx, buffer) in if Cursor.isCursorAtStartOfLine (buffer, cursorIdx) then (* if we are on \n, we don't want to delete or do anything @@ -280,9 +281,19 @@ struct else let val lineStart = Cursor.vi0 (buffer, cursorIdx) - val high = Cursor.viDlrForDelete (buffer, cursorIdx, 1) - 1 + val high = Cursor.viDlrForDelete (buffer, cursorIdx, 1) val length = high - cursorIdx + (* we might want to delete to the end of the file. + * If so, we will append a double-newline. + * The second newline is to comply with Unix-style line endings + * and the first newline provides a place for our cursor to rest. *) + val buffer = + if high > #textLength buffer - 1 then + LineGap.append ("\n\n", buffer) + else + buffer + val buffer = LineGap.goToIdx (high, buffer) val initialMsg = Fn.initMsgs (cursorIdx, length, buffer) val buffer = LineGap.delete (cursorIdx, length, buffer)