textEditor: append, appendEndLine, fixing some bugs

This commit is contained in:
Dustin Swan 2026-04-06 17:55:29 -06:00
parent 586d55df85
commit 24f0046c77
No known key found for this signature in database
GPG key ID: 30D46587E2100467

View file

@ -1,12 +1,13 @@
@textEditor
# TODO
_ = "TODO
# r to repalce
# O to open new line above
# s to seek
# w / b bug, can't select `textEditor` at start of line
# a to append
# smart case searching
";
textEditor = name \
# defaults = {};
@ -104,7 +105,7 @@ textEditor = name \
| StartOfLineChars \ nextWordStart state.lines from.row 0
| EndOfLine \ (
line = nth state.cursorRow state.lines ~ unwrapOr "";
{ row = state.cursorRow, col = (len line) - 1 })
{ row = state.cursorRow, col = (len line) })
| FirstLine \ (
line = nth 0 state.lines ~ unwrapOr "";
{ row = 0, col = len line - 1 })
@ -173,7 +174,12 @@ textEditor = name \
emit = []
};
# 'o' key
append = state \ insertMode state.{ cursorCol = state.cursorCol + 1 };
appendEndLine = state \
line = nth state.cursorRow state.lines ~ unwrapOr "";
insertMode state.{ cursorCol = len line };
openLine = state \
stateSnapshot = { lines = state.lines, cursorRow = state.cursorRow, cursorCol = state.cursorCol };
newUndoStack = [stateSnapshot, ...state.undoStack];
@ -190,7 +196,7 @@ textEditor = name \
emit = []
};
escape = state \ { state = state.{ mode = Normal }, emit = [] };
escape = state \ { state = state.{ mode = Normal, pending = None }, emit = [] };
undo = state \ state.undoStack
| [] \ { state = state, emit = [] }
@ -435,6 +441,8 @@ textEditor = name \
| Key { key = "h" } \ withScroll(leftArrow state)
| Key { key = "ArrowRight" } \ withScroll (rightArrow state)
| Key { key = "l" } \ withScroll(rightArrow state)
| Key { key = "a" } \ append state
| Key { key = "A" } \ appendEndLine state
| Key { key = "i" } \ insertMode state
| Key { key = "o" } \ openLine state
| Key { key = "d", ctrl = True } \ scrollHalfDown state ctx
@ -464,8 +472,10 @@ textEditor = name \
| Key { key = "W", ctrl = True, shift = True } \ write state
| Key { key = "A", ctrl = True, shift = True } \ apply state
| Key { key = "Escape" } \ escape state
# any other key or event
| _ \ { state = state.{ pending = None }, emit = [] }
| _ \ { state = state, emit = [] }
),
view = state emit \