From fb6cab7d0d92d4a5be74162ca9bc0d8fa3446185 Mon Sep 17 00:00:00 2001 From: Humza Shahid Date: Sat, 6 Sep 2025 02:46:49 +0100 Subject: [PATCH] fix minor bug when deleting around (with motion like da( or da< or da) or da>). The bug was that, if the last character we delete with the highest index is also the last character at the end of this line, we deleted the range properly but placed the cursor at a linebreak. In this case, the cursor is meant to be a single character before the line break, and after this commit, we have this desired behaviour. --- fcore/normal-mode/normal-delete.sml | 25 ++++++++++++++++++++----- 1 file changed, 20 insertions(+), 5 deletions(-) diff --git a/fcore/normal-mode/normal-delete.sml b/fcore/normal-mode/normal-delete.sml index 1c7404d..e2148c1 100644 --- a/fcore/normal-mode/normal-delete.sml +++ b/fcore/normal-mode/normal-delete.sml @@ -3,10 +3,8 @@ struct open AppType open MailboxType - fun deleteAndFinish (app: app_type, low, length, buffer, time) = + fun finishAfterDeletingBuffer (app: app_type, low, buffer, time) = let - val buffer = LineGap.delete (low, length, buffer) - val searchString = #searchString app val buffer = LineGap.goToStart buffer val initialMsg = [SEARCH (buffer, searchString)] @@ -20,6 +18,11 @@ struct (app, buffer, low, searchList, initialMsg, time) end + fun deleteAndFinish (app: app_type, low, length, buffer, time) = + let val buffer = LineGap.delete (low, length, buffer) + in finishAfterDeletingBuffer (app, low, buffer, time) + end + (* equivalent of vi's 'x' command **) fun helpRemoveChr (app: app_type, buffer, cursorIdx, count, time) = if count = 0 then @@ -507,6 +510,18 @@ struct finishAfterDeleteInside (app, origLow, high, time) end + fun finishDeleteAroundChr (app, low, high, buffer, time) = + let + val length = high - low + 1 + val buffer = LineGap.delete (low, length, buffer) + val buffer = LineGap.goToIdx (low, buffer) + val low = + if Cursor.isCursorAtStartOfLine (buffer, low) then Int.max (low - 1, 0) + else low + in + finishAfterDeletingBuffer (app, low, buffer, time) + end + fun deleteAroundChrOpen (app: app_type, chr, time) = let val {cursorIdx, buffer, ...} = app @@ -519,7 +534,7 @@ struct val high = Cursor.matchPair (buffer, low) in if low = high then NormalFinish.clearMode app - else deleteAndFinish (app, low, high - low + 1, buffer, time) + else finishDeleteAroundChr (app, low, high, buffer, time) end fun deleteAroundChrClose (app: app_type, chr, time) = @@ -534,7 +549,7 @@ struct val low = Cursor.matchPair (buffer, high) in if low = high then NormalFinish.clearMode app - else deleteAndFinish (app, low, high - low + 1, buffer, time) + else finishDeleteAroundChr (app, low, high, buffer, time) end fun deletePair (app: app_type, time) =