From f1ff6c29d609316aeaaa9d8b7910ba70e961b067 Mon Sep 17 00:00:00 2001 From: Dustin Swan Date: Thu, 26 Feb 2026 16:51:34 -0700 Subject: [PATCH] textEditor can save to a textEditorBuffers list with the W command. it can apply back to the original store ref with the A command. Crazy man --- src/cg/06-textEditor.cg | 37 +++++++++++++++++++++++++++++++++++-- 1 file changed, 35 insertions(+), 2 deletions(-) diff --git a/src/cg/06-textEditor.cg b/src/cg/06-textEditor.cg index 9540e8f..5c0414f 100644 --- a/src/cg/06-textEditor.cg +++ b/src/cg/06-textEditor.cg @@ -1,10 +1,31 @@ textEditor = name \ # defaults = {}; # c = { ...defaults, ...config }; + buffersKey = "textEditorBuffers"; + + # load from staging buffers if it exists there. if not, load from source + source = getAt [buffersKey, name] + | None \ getSource name + | Some v \ v; - source = getSource name; lines = split "\n" source; + write = state \ + content = join "\n" state.lines; + { state = state, emit = [rebindAt [buffersKey, name] content] }; + + apply = state \ + content = name & " = " & (join "\n" state.lines) & ";"; + result = eval! content; + _ = debug! "apply" [content, result]; + result + | Defined _ \ { state = state, emit = [] } + | Err msg \ ( + _ = debug! "error applying" []; + { state = state, emit = [] } + ) + | _ \ { state = state, emit = [] }; + insertChar = char state \ newLines = updateAt state.cursorRow (line \ insertCharAt line state.cursorCol char @@ -146,9 +167,21 @@ textEditor = name \ | Normal \ undo state) | Key { key = "r", ctrl = True } \ (state.mode - | Insert \ insertChar "R" state + | Insert \ { state = state, emit = [] } | Normal \ redo state) + | Key { key = "W", shift = True } \ (state.mode + | Insert \ insertChar "W" state + | Normal \ write state) + + | Key { key = "W", shift = True } \ (state.mode + | Insert \ insertChar "W" state + | Normal \ write state) + + | Key { key = "A", shift = True } \ (state.mode + | Insert \ insertChar "A" state + | Normal \ apply state) + | Key { key = "Escape" } \ escape state | Key { key = "Backspace" } \ (state.mode