More editor stuff

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

@ -354,14 +354,16 @@ renderText = config \
gap = c.scale; gap = c.scale;
chars = split "" c.content; chars = split "" c.content;
ui.row { chars == []
children = map (char \ | True \ ui.rect { w = 0, h = 12 * c.scale, color = "transparent" }
getField char font.glyphs | False \ ui.row {
| Some g \ glyphView { glyph = g, scale = c.scale, color = c.color } children = map (char \
| None \ ui.rect { w = charW * c.scale, h = 12 * c.scale } getField char font.glyphs
) chars, | Some g \ glyphView { glyph = g, scale = c.scale, color = c.color }
gap = gap | None \ ui.rect { w = charW * c.scale, h = 12 * c.scale }
}; ) chars,
gap = gap
};
# text : String \ UI # text : String \ UI
text = content \ renderText { content = content }; text = content \ renderText { content = content };

@ -14,7 +14,13 @@ textEditor = name \
backspace = state \ backspace = state \
state.cursorCol == 0 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 \ ( | False \ (
newLines = updateAt state.cursorRow (line \ newLines = updateAt state.cursorRow (line \
before = slice line 0 (state.cursorCol - 1); before = slice line 0 (state.cursorCol - 1);
@ -31,6 +37,9 @@ textEditor = name \
newLines = updateAt state.cursorRow (_ \ before) state.lines; newLines = updateAt state.cursorRow (_ \ before) state.lines;
newLines2 = insertAt (state.cursorRow + 1) after newLines; 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 = [] }; { state = state.{ lines = newLines2, cursorCol = 0, cursorRow = state.cursorRow + 1 }, emit = [] };
clampCursor = state \ clampCursor = state \
@ -39,8 +48,10 @@ textEditor = name \
newRow = max 0 state.cursorRow; newRow = max 0 state.cursorRow;
newRow2 = min (len state.lines - 1) newRow; newRow2 = min (len state.lines - 1) newRow;
newCol = max 0 (state.cursorCol); maxCol = state.mode
newCol2 = min (len line - 1) newCol; | Insert \ len line
| Normal \ max 0 (len line - 1);
newCol2 = min maxCol (max 0 state.cursorCol);
state.{ cursorRow = newRow2, cursorCol = newCol2 }; state.{ cursorRow = newRow2, cursorCol = newCol2 };

Loading…
Cancel
Save