From 7e6d79582fe631eadb1d998af2923b02b72aad65 Mon Sep 17 00:00:00 2001 From: Dustin Swan Date: Thu, 19 Mar 2026 21:06:09 -0600 Subject: [PATCH] $ for end of line. cleaning up some stuff --- src/cg/06-textEditor.cg | 25 ++++++++++++------------- 1 file changed, 12 insertions(+), 13 deletions(-) diff --git a/src/cg/06-textEditor.cg b/src/cg/06-textEditor.cg index da95b59..e9e6ed8 100644 --- a/src/cg/06-textEditor.cg +++ b/src/cg/06-textEditor.cg @@ -93,19 +93,16 @@ textEditor = name \ to = motion | Word \ nextWordStart state.lines from.row from.col | BackWord \ prevWordStart state.lines from.row from.col - | WholeLine \ from - | Cursor \ from; + | WholeLine \ { row = from.row, col = 0, linewise = True } + | EndOfLine \ ( + line = nth state.cursorRow state.lines ~ unwrapOr ""; + { row = state.cursorRow, col = (len line) - 1 }) + | Cursor \ { row = state.cursorRow, col = state.cursorCol + 1 }; { from = from, to = to }; - deleteChar = state \ - line = nth state.cursorRow state.lines ~ unwrapOr []; - newLine = deleteCharAt line state.cursorCol; - newLines = updateAt state.cursorRow (_ \ newLine) state.lines; - { state = state.{ lines = newLines, emit = [] } }; - deleteLine = state \ newLines = [...(take (state.cursorRow) state.lines), ...(drop (state.cursorRow + 1) state.lines)]; - { state = state.{ lines = newLines, emit = [] } }; + { state = state.{ lines = newLines }, emit = [] }; deleteRange = state from to \ line = nth from.row state.lines ~ unwrapOr ""; @@ -119,10 +116,9 @@ textEditor = name \ action = { operator = operator, motion = motion }; stateSnapshot = { lines = state.lines, cursorRow = state.cursorRow, cursorCol = state.cursorCol }; newState = operator - | Delete \ (motion - | WholeLine \ deleteLine state - | Cursor \ deleteChar state - | _ \ { state = deleteRange state target.from target.to, emit = [] }); + | Delete \ (hasField "linewise" target.to + | True \ deleteLine state + | False \ { state = deleteRange state target.from target.to, emit = [] }); { state = clampCursor newState.state.{ undoStack = [stateSnapshot, ...state.undoStack], pending = None, lastAction = Some action }, emit = newState.emit }; moveCursor = motion state \ @@ -329,6 +325,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.pending + | None \ withScroll { state = moveCursor (resolveMotion EndOfLine state) state, emit = [] } + | Some Delete \ withScroll (applyOperator Delete EndOfLine state)) | Key { key = "." } \ (state.lastAction | None \ { state = state, emit = [] } | Some action \ applyOperator action.operator action.motion state)