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