x to delete char

This commit is contained in:
Dustin Swan 2026-03-19 20:40:38 -06:00
parent 0d43dc0128
commit d0e900a974
No known key found for this signature in database
GPG key ID: 30D46587E2100467
2 changed files with 15 additions and 1 deletions

View file

@ -44,6 +44,11 @@ insertCharAt = text pos char \
after = slice text pos (len text);
before & char & after;
deleteCharAt = text pos \
before = slice text 0 pos;
after = slice text (pos + 1) (len text);
before & after;
# updateAt
updateAt = i f list \ mapWithIndex (x j \
(i == j | True \ f x | False \ x)

View file

@ -93,9 +93,16 @@ textEditor = name \
to = motion
| Word \ nextWordStart state.lines from.row from.col
| BackWord \ prevWordStart state.lines from.row from.col
| WholeLine \ from;
| WholeLine \ from
| Cursor \ from;
{ from = from, to = to };
deleteChar = state \
line = nth state.cursorRow state.lines ~ unwrapOr [];
newLine = deleteCharAt line state.cursorCol;
newLines = updateAt state.cursorRow (_ \ newLine) state.lines;
{ state = state.{ lines = newLines, emit = [] } };
deleteLine = state \
newLines = [...(take (state.cursorRow) state.lines), ...(drop (state.cursorRow + 1) state.lines)];
{ state = state.{ lines = newLines, emit = [] } };
@ -114,6 +121,7 @@ textEditor = name \
newState = operator
| Delete \ (motion
| WholeLine \ deleteLine state
| Cursor \ deleteChar state
| _ \ { state = deleteRange state target.from target.to, emit = [] });
{ state = clampCursor newState.state.{ undoStack = [stateSnapshot, ...state.undoStack], pending = None, lastAction = Some action }, emit = newState.emit };
@ -311,6 +319,7 @@ textEditor = name \
| Key { key = "u", ctrl = True } \ scrollHalfUp state ctx
| Key { key = "u" } \ undo state
| Key { key = "r", ctrl = True } \ redo state
| Key { key = "x" } \ applyOperator Delete Cursor state
| Key { key = "d" } \ (state.pending
| Some Delete \ applyOperator Delete WholeLine state
| _ \ { state = state.{ pending = Some Delete }, emit = [] })