From 0d43dc01284e46d059dfe292e880b9d7000a5e04 Mon Sep 17 00:00:00 2001 From: Dustin Swan Date: Thu, 19 Mar 2026 20:21:26 -0600 Subject: [PATCH] dot in textEditor to repeat last action --- src/cg/06-textEditor.cg | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/src/cg/06-textEditor.cg b/src/cg/06-textEditor.cg index 0220583..ae12a39 100644 --- a/src/cg/06-textEditor.cg +++ b/src/cg/06-textEditor.cg @@ -109,12 +109,13 @@ textEditor = name \ applyOperator = operator motion state \ target = resolveMotion motion state; + action = { operator = operator, motion = motion }; stateSnapshot = { lines = state.lines, cursorRow = state.cursorRow, cursorCol = state.cursorCol }; newState = operator | Delete \ (motion | WholeLine \ deleteLine state | _ \ { state = deleteRange state target.from target.to, emit = [] }); - { state = clampCursor newState.state.{ undoStack = [stateSnapshot, ...state.undoStack], pending = None }, emit = newState.emit }; + { state = clampCursor newState.state.{ undoStack = [stateSnapshot, ...state.undoStack], pending = None, lastAction = Some action }, emit = newState.emit }; moveCursor = motion state \ state.{ cursorCol = motion.to.col, cursorRow = motion.to.row }; @@ -276,7 +277,8 @@ textEditor = name \ undoStack = [], redoStack = [], mode = Normal, # Normal | Insert | Visual - pending = None # Some "d" | Some "g" | etc. + pending = None, # Some "d" | Some "g" | etc. + lastAction = None, # Some { operator, motion } }, update = state event \ state.mode @@ -318,6 +320,9 @@ textEditor = name \ | Key { key = "w" } \ (state.pending | None \ withScroll { state = moveCursor (resolveMotion Word state) state, emit = [] } | Some Delete \ withScroll (applyOperator Delete Word state)) + | Key { key = "." } \ (state.lastAction + | None \ { state = state, emit = [] } + | Some action \ applyOperator action.operator action.motion state) | Key { key = "W", ctrl = True, shift = True } \ write state | Key { key = "A", ctrl = True, shift = True } \ apply state # any other key or event