From f848d4f301a192792e1b17a439b5c53cd04f6c29 Mon Sep 17 00:00:00 2001 From: Humza Shahid Date: Thu, 7 Aug 2025 23:33:40 +0100 Subject: [PATCH] done implementing 'deleteInside' and 'deleteAroundd' commands --- fcore/normal-mode/normal-delete.sml | 30 +++++++++++++++++++++++++++++ fcore/normal-mode/normal-mode.sml | 21 ++++++++++++++++++++ 2 files changed, 51 insertions(+) diff --git a/fcore/normal-mode/normal-delete.sml b/fcore/normal-mode/normal-delete.sml index 4869983..778679c 100644 --- a/fcore/normal-mode/normal-delete.sml +++ b/fcore/normal-mode/normal-delete.sml @@ -449,4 +449,34 @@ struct in finishAfterDeleteInside (app, origLow, high) end + + fun deleteAroundChrOpen (app: app_type, chr) = + let + val {cursorIdx, buffer, ...} = app + + val start = cursorIdx + 1 + val buffer = LineGap.goToIdx (start, buffer) + + val low = Cursor.toPrevChr (buffer, start, chr) + val buffer = LineGap.goToIdx (low, buffer) + val high = Cursor.matchPair (buffer, low) + in + if low = high then Finish.clearMode app + else deleteAndFinish (app, low, high - low + 1, buffer) + end + + fun deleteAroundChrClose (app: app_type, chr) = + let + val {cursorIdx, buffer, ...} = 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 low = Cursor.matchPair (buffer, high) + in + if low = high then Finish.clearMode app + else deleteAndFinish (app, low, high - low + 1, buffer) + end end diff --git a/fcore/normal-mode/normal-mode.sml b/fcore/normal-mode/normal-mode.sml index 3b4b273..47b2120 100644 --- a/fcore/normal-mode/normal-mode.sml +++ b/fcore/normal-mode/normal-mode.sml @@ -125,6 +125,18 @@ struct | #">" => NormalDelete.deleteInsideChrClose (app, chr) | _ => Finish.clearMode app + fun parseDeleteAround (app, chr) = + case chr of + #"(" => NormalDelete.deleteInsideChrOpen (app, chr) + | #"[" => NormalDelete.deleteInsideChrOpen (app, chr) + | #"{" => NormalDelete.deleteInsideChrOpen (app, chr) + | #"<" => NormalDelete.deleteInsideChrOpen (app, chr) + | #")" => NormalDelete.deleteAroundChrClose (app, chr) + | #"]" => NormalDelete.deleteAroundChrClose (app, chr) + | #"}" => NormalDelete.deleteAroundChrClose (app, chr) + | #">" => NormalDelete.deleteAroundChrClose (app, chr) + | _ => Finish.clearMode app + fun parseDelete (strPos, str, count, app, newCmd) = if strPos = String.size str - 1 then (* have to check newCmd *) @@ -161,6 +173,7 @@ struct | #"F" => appendChr (app, chr, str) | #"g" => appendChr (app, chr, str) | #"i" => appendChr (app, chr, str) + | #"a" => appendChr (app, chr, str) (* invalid command: reset mode *) | _ => Finish.clearMode app) | KEY_ESC => Finish.clearMode app @@ -232,6 +245,14 @@ struct Finish.resizeText (app, width, height) | WITH_SEARCH_LIST searchList => Finish.withSearchList (app, searchList)) + | #"a" => + (case newCmd of + CHAR_EVENT chr => parseDeleteAround (app, chr) + | KEY_ESC => Finish.clearMode app + | RESIZE_EVENT (width, height) => + Finish.resizeText (app, width, height) + | WITH_SEARCH_LIST searchList => + Finish.withSearchList (app, searchList)) | _ => Finish.clearMode app (* useful reference as list of non-terminal commands *)