From 24f0046c771025662d09cbad15c7704b498550d7 Mon Sep 17 00:00:00 2001 From: Dustin Swan Date: Mon, 6 Apr 2026 17:55:29 -0600 Subject: [PATCH] textEditor: append, appendEndLine, fixing some bugs --- src/cg/textEditor.cg | 20 +++++++++++++++----- 1 file changed, 15 insertions(+), 5 deletions(-) diff --git a/src/cg/textEditor.cg b/src/cg/textEditor.cg index 8142a4b..28c7caf 100644 --- a/src/cg/textEditor.cg +++ b/src/cg/textEditor.cg @@ -1,12 +1,13 @@ @textEditor -# TODO +_ = "TODO # r to repalce # O to open new line above # s to seek # w / b bug, can't select `textEditor` at start of line # a to append # smart case searching +"; textEditor = name \ # defaults = {}; @@ -104,7 +105,7 @@ textEditor = name \ | StartOfLineChars \ nextWordStart state.lines from.row 0 | EndOfLine \ ( line = nth state.cursorRow state.lines ~ unwrapOr ""; - { row = state.cursorRow, col = (len line) - 1 }) + { row = state.cursorRow, col = (len line) }) | FirstLine \ ( line = nth 0 state.lines ~ unwrapOr ""; { row = 0, col = len line - 1 }) @@ -173,7 +174,12 @@ textEditor = name \ emit = [] }; - # 'o' key + append = state \ insertMode state.{ cursorCol = state.cursorCol + 1 }; + + appendEndLine = state \ + line = nth state.cursorRow state.lines ~ unwrapOr ""; + insertMode state.{ cursorCol = len line }; + openLine = state \ stateSnapshot = { lines = state.lines, cursorRow = state.cursorRow, cursorCol = state.cursorCol }; newUndoStack = [stateSnapshot, ...state.undoStack]; @@ -190,7 +196,7 @@ textEditor = name \ emit = [] }; - escape = state \ { state = state.{ mode = Normal }, emit = [] }; + escape = state \ { state = state.{ mode = Normal, pending = None }, emit = [] }; undo = state \ state.undoStack | [] \ { state = state, emit = [] } @@ -435,6 +441,8 @@ textEditor = name \ | Key { key = "h" } \ withScroll(leftArrow state) | Key { key = "ArrowRight" } \ withScroll (rightArrow state) | Key { key = "l" } \ withScroll(rightArrow state) + | Key { key = "a" } \ append state + | Key { key = "A" } \ appendEndLine state | Key { key = "i" } \ insertMode state | Key { key = "o" } \ openLine state | Key { key = "d", ctrl = True } \ scrollHalfDown state ctx @@ -464,8 +472,10 @@ textEditor = name \ | Key { key = "W", ctrl = True, shift = True } \ write state | Key { key = "A", ctrl = True, shift = True } \ apply state + + | Key { key = "Escape" } \ escape state # any other key or event - | _ \ { state = state.{ pending = None }, emit = [] } + | _ \ { state = state, emit = [] } ), view = state emit \