More editor stuff

master
Dustin Swan 1 day ago
parent 735db38a2f
commit 63f599b850
Signed by: dustinswan
GPG Key ID: 30D46587E2100467

@ -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 };

@ -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 };

Loading…
Cancel
Save