From e2acdd90f44e9eb6a545174bf66b82f48f5fd787 Mon Sep 17 00:00:00 2001 From: Humza Shahid Date: Sun, 7 Sep 2025 22:30:39 +0100 Subject: [PATCH] new implementation for removing characters with 'x', which is simpler than previous implementation as well --- fcore/normal-mode/make-normal-delete.sml | 33 +++++++++++++++++++++++- 1 file changed, 32 insertions(+), 1 deletion(-) diff --git a/fcore/normal-mode/make-normal-delete.sml b/fcore/normal-mode/make-normal-delete.sml index 6c865d5..0877053 100644 --- a/fcore/normal-mode/make-normal-delete.sml +++ b/fcore/normal-mode/make-normal-delete.sml @@ -89,7 +89,38 @@ struct end fun removeChr (app: app_type, count, time) = - helpRemoveChr (app, #buffer app, #cursorIdx app, count, time) + let + val {buffer, cursorIdx, ...} = app + + val buffer = LineGap.goToIdx (cursorIdx, buffer) + val lineStart = Cursor.vi0 (buffer, cursorIdx) + val lineEnd = Cursor.viDlr (buffer, cursorIdx, 1) + + val buffer = LineGap.goToIdx (lineEnd, buffer) + in + if + cursorIdx = lineEnd + andalso Cursor.isCursorAtStartOfLine (buffer, lineEnd) + then + NormalFinish.clearMode app + else + let + val lineEnd = Cursor.viDlrForDelete (buffer, cursorIdx, 1) + val high = cursorIdx + count + val high = Int.min (lineEnd, high) + val length = high - cursorIdx + + val initialMsg = Fn.initMsgs (cursorIdx, length, buffer) + val buffer = LineGap.delete (cursorIdx, length, buffer) + + (* figure out where to place cursor *) + val buffer = LineGap.goToIdx (lineStart, buffer) + val lineEndAfterDelete = Cursor.viDlr (buffer, lineStart, 1) + val cursorIdx = Int.min (lineEndAfterDelete, cursorIdx) + in + finishAfterDeletingBuffer (app, cursorIdx, buffer, time, initialMsg) + end + end (* Note: The below implementation of removing line breaks with the 'J' * command slightly differs from the implementation in Vim.