From a90cdf794352e894f68740dcc4a6c1966295e3f0 Mon Sep 17 00:00:00 2001 From: Humza Shahid Date: Tue, 2 Sep 2025 11:35:29 +0100 Subject: [PATCH] implement a couple of more yank operations --- fcore/normal-mode/normal-mode-with.sml | 29 ++++++++++++ fcore/normal-mode/normal-mode.sml | 61 ++++++++++++++++++++------ 2 files changed, 77 insertions(+), 13 deletions(-) diff --git a/fcore/normal-mode/normal-mode-with.sml b/fcore/normal-mode/normal-mode-with.sml index 8b21f13..fd8b9c3 100644 --- a/fcore/normal-mode/normal-mode-with.sml +++ b/fcore/normal-mode/normal-mode-with.sml @@ -103,6 +103,35 @@ struct } end + fun modeAndBuffer (app: app_type, newBuffer, newMode, newMsgs) = + let + val + { mode = _ + , msgs = _ + , buffer = _ + , bufferModifyTime + , searchList + , searchString + , cursorIdx + , windowWidth + , windowHeight + , startLine + } = app + in + { mode = newMode + , msgs = newMsgs + , buffer = newBuffer + , bufferModifyTime = bufferModifyTime + , searchList = searchList + , searchString = searchString + , cursorIdx = cursorIdx + , windowWidth = windowWidth + , windowHeight = windowHeight + , startLine = startLine + } + end + + fun searchList ( app: app_type , newSearchList diff --git a/fcore/normal-mode/normal-mode.sml b/fcore/normal-mode/normal-mode.sml index b61329c..b7506d8 100644 --- a/fcore/normal-mode/normal-mode.sml +++ b/fcore/normal-mode/normal-mode.sml @@ -216,7 +216,7 @@ struct val msg = YANK str val mode = NORMAL_MODE "" in - NormalModeWith.mode (app, mode, [DRAW msg]) + NormalModeWith.modeAndBuffer (app, buffer, mode, [DRAW msg]) end fun yankWhenMovingForward (app: app_type, fMove, count) = @@ -236,7 +236,7 @@ struct val msg = YANK str val mode = NORMAL_MODE "" in - NormalModeWith.mode (app, mode, [DRAW msg]) + NormalModeWith.modeAndBuffer (app, buffer, mode, [DRAW msg]) end fun parseYankTerminal (str, count, app, chrCmd, time) = @@ -261,7 +261,7 @@ struct val msg = YANK str val mode = NORMAL_MODE "" in - NormalModeWith.mode (app, mode, [DRAW msg]) + NormalModeWith.modeAndBuffer (app, buffer, mode, [DRAW msg]) end | #"0" => let val f = fn (buffer, cursorIdx, _) => Cursor.vi0 (buffer, cursorIdx) @@ -295,19 +295,54 @@ struct val msg = YANK str val mode = NORMAL_MODE "" in - NormalModeWith.mode (app, mode, [DRAW msg]) + NormalModeWith.modeAndBuffer (app, buffer, mode, [DRAW msg]) end - (* todo: | #"G" => - (* if str has a size larger than 0, - * interpret as "go to line" command; - * else, interpret as a command to move to end *) - if String.size str = 0 then NormalMove.moveToEnd app - else NormalMove.moveToLine (app, count - 1) - | #"%" => NormalMove.moveToMatchingPair app - *) + let + open DrawMsg + open MailboxType - (* todo: non-terminal chars *) + val {buffer, cursorIdx, ...} = app + + val buffer = LineGap.goToEnd buffer + val {rightStrings, idx, ...} = buffer + val finishIdx = Int.max (0, idx - 1) + + val length = finishIdx - cursorIdx + val str = LineGap.substring (cursorIdx, length, buffer) + + val msg = YANK str + val mode = NORMAL_MODE "" + in + NormalModeWith.modeAndBuffer (app, buffer, mode, [DRAW msg]) + end + | #"%" => + let + open DrawMsg + open MailboxType + + val {buffer, cursorIdx, ...} = app + + val otherIdx = Cursor.matchPair (buffer, cursorIdx) + in + if cursorIdx = otherIdx then + NormalFinish.clearMode app + else + let + val low = Int.min (cursorIdx, otherIdx) + val high = Int.max (cursorIdx, otherIdx) + val length = high - low + 1 + + val buffer = LineGap.goToIdx (high, buffer) + 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 + (* todo: non-terminal chars, 'n' (go to next match) *) | _ => NormalFinish.clearMode app fun parseYank (strPos, str, count, app, chrCmd, time) =