From 1bdf8e457b00af8a86c3d455605b34c90b0a871b Mon Sep 17 00:00:00 2001 From: Humza Shahid Date: Thu, 7 Aug 2025 19:12:01 +0100 Subject: [PATCH] implement 'deleteInside' motions --- fcore/normal-mode/normal-delete.sml | 67 ++++++++++++++++++++++++++++- fcore/normal-mode/normal-mode.sml | 18 ++++++-- fcore/normal-mode/normal-move.sml | 1 - 3 files changed, 81 insertions(+), 5 deletions(-) diff --git a/fcore/normal-mode/normal-delete.sml b/fcore/normal-mode/normal-delete.sml index 954aa54..e1442f6 100644 --- a/fcore/normal-mode/normal-delete.sml +++ b/fcore/normal-mode/normal-delete.sml @@ -431,8 +431,73 @@ struct val buffer = LineGap.goToIdx (low, buffer) in - Finish.buildTextAndClear (app, buffer, low, searchList, initialMsg) end end + + fun deleteInsideChrOpen (app: app_type, chr) = + let + val {cursorIdx, buffer, searchString, ...} = app + + val start = cursorIdx + 1 + val buffer = LineGap.goToIdx (start, buffer) + + val origLow = Cursor.toPrevChr (buffer, start, chr) + val buffer = LineGap.goToIdx (origLow, buffer) + val high = Cursor.matchPair (buffer, origLow) + in + if origLow = high then + Finish.clearMode app + else + let + val low = origLow + 1 + val length = high - low + val buffer = LineGap.delete (low, length, buffer) + + val buffer = LineGap.goToEnd buffer + val initialMsg = [SEARCH (buffer, searchString)] + + val buffer = LineGap.goToIdx (low + 777, buffer) + val searchList = + SearchList.buildRange (buffer, searchString, low - 777) + + val buffer = LineGap.goToIdx (origLow, buffer) + in + Finish.buildTextAndClear + (app, buffer, origLow, searchList, initialMsg) + end + end + + fun deleteInsideChrClose (app: app_type, chr) = + let + val {cursorIdx, buffer, searchString, ...} = app + + val start = Int.max (cursorIdx - 1, 0) + val buffer = LineGap.goToIdx (start, buffer) + + val high = Cursor.toNextChr (buffer, start, chr) + val buffer = LineGap.goToIdx (high, buffer) + val origLow = Cursor.matchPair (buffer, high) + in + if origLow = high then + Finish.clearMode app + else + let + val low = origLow + 1 + val length = high - low + val buffer = LineGap.delete (low, length, buffer) + + val buffer = LineGap.goToEnd buffer + val initialMsg = [SEARCH (buffer, searchString)] + + val buffer = LineGap.goToIdx (low + 777, buffer) + val searchList = + SearchList.buildRange (buffer, searchString, low - 777) + + val buffer = LineGap.goToIdx (origLow, buffer) + in + Finish.buildTextAndClear + (app, buffer, origLow, searchList, initialMsg) + end + end end diff --git a/fcore/normal-mode/normal-mode.sml b/fcore/normal-mode/normal-mode.sml index d9a102a..3b4b273 100644 --- a/fcore/normal-mode/normal-mode.sml +++ b/fcore/normal-mode/normal-mode.sml @@ -111,6 +111,20 @@ struct AppWith.mode (app, mode, []) end + fun parseDeleteInside (app, chr) = + case chr of + #"w" => NormalDelete.deleteInsideWord app + | #"W" => NormalDelete.deleteInsideWORD app + | #"(" => NormalDelete.deleteInsideChrOpen (app, chr) + | #"[" => NormalDelete.deleteInsideChrOpen (app, chr) + | #"{" => NormalDelete.deleteInsideChrOpen (app, chr) + | #"<" => NormalDelete.deleteInsideChrOpen (app, chr) + | #")" => NormalDelete.deleteInsideChrClose (app, chr) + | #"]" => NormalDelete.deleteInsideChrClose (app, chr) + | #"}" => NormalDelete.deleteInsideChrClose (app, chr) + | #">" => NormalDelete.deleteInsideChrClose (app, chr) + | _ => Finish.clearMode app + fun parseDelete (strPos, str, count, app, newCmd) = if strPos = String.size str - 1 then (* have to check newCmd *) @@ -212,9 +226,7 @@ struct Finish.withSearchList (app, searchList)) | #"i" => (case newCmd of - CHAR_EVENT #"w" => NormalDelete.deleteInsideWord app - | CHAR_EVENT #"W" => NormalDelete.deleteInsideWORD app - | CHAR_EVENT _ => Finish.clearMode app + CHAR_EVENT chr => parseDeleteInside (app, chr) | KEY_ESC => Finish.clearMode app | RESIZE_EVENT (width, height) => Finish.resizeText (app, width, height) diff --git a/fcore/normal-mode/normal-move.sml b/fcore/normal-mode/normal-move.sml index 6066ea6..e1488b2 100644 --- a/fcore/normal-mode/normal-move.sml +++ b/fcore/normal-mode/normal-move.sml @@ -249,5 +249,4 @@ struct Finish.buildTextAndClearAfterChr (app, buffer, newCursorIdx, searchList, []) end - end