From 63f599b850fb3bbac83082259c355c5a4dd30a6b Mon Sep 17 00:00:00 2001 From: Dustin Swan Date: Wed, 25 Feb 2026 23:27:06 -0700 Subject: [PATCH] More editor stuff --- src/cg/03-ui-components.cg | 18 ++++++++++-------- src/cg/06-textEditor.cg | 17 ++++++++++++++--- 2 files changed, 24 insertions(+), 11 deletions(-) diff --git a/src/cg/03-ui-components.cg b/src/cg/03-ui-components.cg index 8af233f..5ca8f0e 100644 --- a/src/cg/03-ui-components.cg +++ b/src/cg/03-ui-components.cg @@ -354,14 +354,16 @@ renderText = config \ gap = c.scale; chars = split "" c.content; - ui.row { - children = map (char \ - getField char font.glyphs - | Some g \ glyphView { glyph = g, scale = c.scale, color = c.color } - | None \ ui.rect { w = charW * c.scale, h = 12 * c.scale } - ) chars, - gap = gap - }; + chars == [] + | True \ ui.rect { w = 0, h = 12 * c.scale, color = "transparent" } + | False \ ui.row { + children = map (char \ + getField char font.glyphs + | Some g \ glyphView { glyph = g, scale = c.scale, color = c.color } + | None \ ui.rect { w = charW * c.scale, h = 12 * c.scale } + ) chars, + gap = gap + }; # text : String \ UI text = content \ renderText { content = content }; diff --git a/src/cg/06-textEditor.cg b/src/cg/06-textEditor.cg index 737d70f..daf420d 100644 --- a/src/cg/06-textEditor.cg +++ b/src/cg/06-textEditor.cg @@ -14,7 +14,13 @@ textEditor = name \ backspace = state \ state.cursorCol == 0 - | True \ { state = state, emit = [] } # todo, join line, if not at row 0 + | True \ ( + state.cursorRow == 0 + | True \ { state = state, emit = [] } + | False \ ( + { state = state, emit = [] } # todo, join with previous line + ) + ) | False \ ( newLines = updateAt state.cursorRow (line \ before = slice line 0 (state.cursorCol - 1); @@ -31,6 +37,9 @@ textEditor = name \ newLines = updateAt state.cursorRow (_ \ before) state.lines; newLines2 = insertAt (state.cursorRow + 1) after newLines; + _ = debug! "enter" { before = before, after = after, newLines2 = newLines2, newRow = + state.cursorRow + 1 }; + { state = state.{ lines = newLines2, cursorCol = 0, cursorRow = state.cursorRow + 1 }, emit = [] }; clampCursor = state \ @@ -39,8 +48,10 @@ textEditor = name \ newRow = max 0 state.cursorRow; newRow2 = min (len state.lines - 1) newRow; - newCol = max 0 (state.cursorCol); - newCol2 = min (len line - 1) newCol; + maxCol = state.mode + | Insert \ len line + | Normal \ max 0 (len line - 1); + newCol2 = min maxCol (max 0 state.cursorCol); state.{ cursorRow = newRow2, cursorCol = newCol2 };