From 6cd038cf81dd080c5a2ad73554ad063969e2f1d9 Mon Sep 17 00:00:00 2001 From: Humza Shahid Date: Tue, 2 Sep 2025 12:46:30 +0100 Subject: [PATCH] done refactoring terminal yank commands --- fcore/normal-mode/normal-mode.sml | 45 ++----------------------------- fcore/normal-mode/normal-yank.sml | 39 +++++++++++++++++++++++++++ 2 files changed, 41 insertions(+), 43 deletions(-) diff --git a/fcore/normal-mode/normal-mode.sml b/fcore/normal-mode/normal-mode.sml index b3fc443..3eda903 100644 --- a/fcore/normal-mode/normal-mode.sml +++ b/fcore/normal-mode/normal-mode.sml @@ -259,49 +259,8 @@ struct | #"^" => NormalYank.yankToFirstNonSpaceChr app | #"G" => NormalYank.yankToEndOfText app | #"%" => NormalYank.yankToMatchingPair app - | #"n" => - let - open DrawMsg - open MailboxType - - val {cursorIdx, searchList, buffer, ...} = app - val high = SearchList.nextMatch (cursorIdx, searchList, count) - in - if high = ~1 orelse high <= cursorIdx then - NormalFinish.clearMode app - else - let - val length = high - cursorIdx - val buffer = LineGap.goToIdx (high, buffer) - - val str = LineGap.substring (cursorIdx, length, buffer) - val msg = YANK str - val mode = NORMAL_MODE "" - in - NormalModeWith.modeAndBuffer (app, buffer, mode, [DRAW msg]) - end - end - | #"N" => - let - open DrawMsg - open MailboxType - - val {cursorIdx, searchList, buffer, ...} = app - val low = SearchList.prevMatch (cursorIdx, searchList, count) - in - if low = ~1 orelse low >= cursorIdx then - NormalFinish.clearMode app - else - let - val length = cursorIdx - low - - val str = LineGap.substring (low, length, buffer) - val msg = YANK str - val mode = NORMAL_MODE "" - in - NormalModeWith.modeAndBuffer (app, buffer, mode, [DRAW msg]) - end - end + | #"n" => NormalYank.yankToNextMatch (app, count) + | #"N" => NormalYank.yankToPrevMatch (app, count) (* todo: non-terminal chars *) | _ => NormalFinish.clearMode app diff --git a/fcore/normal-mode/normal-yank.sml b/fcore/normal-mode/normal-yank.sml index 1d75d97..82e3c4e 100644 --- a/fcore/normal-mode/normal-yank.sml +++ b/fcore/normal-mode/normal-yank.sml @@ -149,4 +149,43 @@ struct NormalModeWith.modeAndBuffer (app, buffer, mode, [DRAW msg]) end end + + fun yankToNextMatch (app: app_type, count) = + let + val {cursorIdx, searchList, buffer, ...} = app + val high = SearchList.nextMatch (cursorIdx, searchList, count) + in + if high = ~1 orelse high <= cursorIdx then + NormalFinish.clearMode app + else + let + val length = high - cursorIdx + val buffer = LineGap.goToIdx (high, buffer) + + val str = LineGap.substring (cursorIdx, length, buffer) + val msg = YANK str + val mode = NORMAL_MODE "" + in + NormalModeWith.modeAndBuffer (app, buffer, mode, [DRAW msg]) + end + end + + fun yankToPrevMatch (app: app_type, count) = + let + val {cursorIdx, searchList, buffer, ...} = app + val low = SearchList.prevMatch (cursorIdx, searchList, count) + in + if low = ~1 orelse low >= cursorIdx then + NormalFinish.clearMode app + else + let + val length = cursorIdx - low + + val str = LineGap.substring (low, length, buffer) + val msg = YANK str + val mode = NORMAL_MODE "" + in + NormalModeWith.modeAndBuffer (app, buffer, mode, [DRAW msg]) + end + end end