From 7a97ec3f90d7b08e047b1bb72c012acf83e37b01 Mon Sep 17 00:00:00 2001 From: Dustin Swan Date: Wed, 4 Mar 2026 17:56:53 -0700 Subject: [PATCH] texteditor. 'o' key --- src/cg/01-stdlib.cg | 10 ++++++++++ src/cg/06-textEditor.cg | 20 ++++++++++++++++++++ 2 files changed, 30 insertions(+) diff --git a/src/cg/01-stdlib.cg b/src/cg/01-stdlib.cg index cfb63bf..b05de06 100644 --- a/src/cg/01-stdlib.cg +++ b/src/cg/01-stdlib.cg @@ -77,6 +77,16 @@ join = s list \ list | [x] \ x | [x, ...xs] \ (x & s & (join s xs)); +# repeatStr : Int \ String \ String +repeatStr = n str \ n + | 0 \ "" + | m \ str & (repeatStr (m - 1) str); + +# repeat : Int \ a \ List a +repeat = n a \ n + | 0 \ [] + | m \ [a, ...repeat (m - 1) a]; + # zipWith : (a \ b \ c) \ List a \ List b \ List c zipWith = f l1 l2 \ l1 | [] \ [] diff --git a/src/cg/06-textEditor.cg b/src/cg/06-textEditor.cg index c626821..81de2ca 100644 --- a/src/cg/06-textEditor.cg +++ b/src/cg/06-textEditor.cg @@ -52,6 +52,22 @@ textEditor = name \ emit = [] }; + # 'o' key + openLine = state \ + stateSnapshot = { lines = state.lines, cursorRow = state.cursorRow, cursorCol = state.cursorCol }; + newUndoStack = [stateSnapshot, ...state.undoStack]; + cursorRow = state.cursorRow + 1; + newLines = insertAt cursorRow "" state.lines; + { + state = state.{ + lines = newLines, + cursorRow = cursorRow, + undoStack = newUndoStack, + mode = Insert + }, + emit = [] + }; + escape = state \ { state = state.{ mode = Normal }, emit = [] }; undo = state \ state.undoStack @@ -206,6 +222,10 @@ textEditor = name \ | Insert \ insertChar "i" state | Normal \ insertMode state) + | Key { key = "o" } \ (state.mode + | Insert \ insertChar "o" state + | Normal \ openLine state) + | Key { key = "d", ctrl = True } \ scrollHalfDown state ctx | Key { key = "u", ctrl = True } \ scrollHalfUp state ctx