From a8e879289de2833641af7add6ca6b5ab49dc891a Mon Sep 17 00:00:00 2001 From: Dustin Swan Date: Sat, 21 Mar 2026 11:31:47 -0600 Subject: [PATCH] More vi motions --- src/cg/06-textEditor.cg | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/src/cg/06-textEditor.cg b/src/cg/06-textEditor.cg index 42cd9be..1075d23 100644 --- a/src/cg/06-textEditor.cg +++ b/src/cg/06-textEditor.cg @@ -94,9 +94,18 @@ textEditor = name \ | Word \ nextWordStart state.lines from.row from.col | BackWord \ prevWordStart state.lines from.row from.col | WholeLine \ { row = from.row, col = 0, linewise = True } + | StartOfLine \ { row = from.row, col = 0 } + | StartOfLineChars \ nextWordStart state.lines from.row 0 | EndOfLine \ ( line = nth state.cursorRow state.lines ~ unwrapOr ""; { row = state.cursorRow, col = (len line) - 1 }) + | FirstLine \ ( + line = nth 0 state.lines ~ unwrapOr ""; + { row = 0, col = len line - 1 }) + | LastLine \ ( + lastRow = len state.lines - 1; + line = nth lastRow state.lines ~ unwrapOr ""; + { row = lastRow, col = len line - 1 }) | Cursor \ { row = state.cursorRow, col = state.cursorCol + 1 }; { from = from, to = to }; @@ -326,14 +335,20 @@ textEditor = name \ | _ \ { state = state.{ pending = Some Delete }, emit = [] }) | Key { key = "b" } \ handleMotion BackWord state | Key { key = "w" } \ handleMotion Word state + | Key { key = "0" } \ handleMotion StartOfLine state + | Key { key = "^" } \ handleMotion StartOfLineChars state | Key { key = "$" } \ handleMotion EndOfLine state + | Key { key = "g" } \ (state.pending + | Some "g" \ handleMotion FirstLine state.{ pending = None } + | _ \ { state = state.{ pending = Some "g" }, emit = [] }) + | Key { key = "G" } \ handleMotion LastLine 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 - | _ \ { state = state, emit = [] } + | _ \ { state = state.{ pending = None }, emit = [] } ), view = state emit \