x to delete char
This commit is contained in:
parent
0d43dc0128
commit
d0e900a974
2 changed files with 15 additions and 1 deletions
|
|
@ -44,6 +44,11 @@ insertCharAt = text pos char \
|
||||||
after = slice text pos (len text);
|
after = slice text pos (len text);
|
||||||
before & char & after;
|
before & char & after;
|
||||||
|
|
||||||
|
deleteCharAt = text pos \
|
||||||
|
before = slice text 0 pos;
|
||||||
|
after = slice text (pos + 1) (len text);
|
||||||
|
before & after;
|
||||||
|
|
||||||
# updateAt
|
# updateAt
|
||||||
updateAt = i f list \ mapWithIndex (x j \
|
updateAt = i f list \ mapWithIndex (x j \
|
||||||
(i == j | True \ f x | False \ x)
|
(i == j | True \ f x | False \ x)
|
||||||
|
|
|
||||||
|
|
@ -93,9 +93,16 @@ textEditor = name \
|
||||||
to = motion
|
to = motion
|
||||||
| Word \ nextWordStart state.lines from.row from.col
|
| Word \ nextWordStart state.lines from.row from.col
|
||||||
| BackWord \ prevWordStart state.lines from.row from.col
|
| BackWord \ prevWordStart state.lines from.row from.col
|
||||||
| WholeLine \ from;
|
| WholeLine \ from
|
||||||
|
| Cursor \ from;
|
||||||
{ from = from, to = to };
|
{ 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 \
|
deleteLine = state \
|
||||||
newLines = [...(take (state.cursorRow) state.lines), ...(drop (state.cursorRow + 1) state.lines)];
|
newLines = [...(take (state.cursorRow) state.lines), ...(drop (state.cursorRow + 1) state.lines)];
|
||||||
{ state = state.{ lines = newLines, emit = [] } };
|
{ state = state.{ lines = newLines, emit = [] } };
|
||||||
|
|
@ -114,6 +121,7 @@ textEditor = name \
|
||||||
newState = operator
|
newState = operator
|
||||||
| Delete \ (motion
|
| Delete \ (motion
|
||||||
| WholeLine \ deleteLine state
|
| WholeLine \ deleteLine state
|
||||||
|
| Cursor \ deleteChar state
|
||||||
| _ \ { state = deleteRange state target.from target.to, emit = [] });
|
| _ \ { state = deleteRange state target.from target.to, emit = [] });
|
||||||
{ state = clampCursor newState.state.{ undoStack = [stateSnapshot, ...state.undoStack], pending = None, lastAction = Some action }, emit = newState.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", ctrl = True } \ scrollHalfUp state ctx
|
||||||
| Key { key = "u" } \ undo state
|
| Key { key = "u" } \ undo state
|
||||||
| Key { key = "r", ctrl = True } \ redo state
|
| Key { key = "r", ctrl = True } \ redo state
|
||||||
|
| Key { key = "x" } \ applyOperator Delete Cursor state
|
||||||
| Key { key = "d" } \ (state.pending
|
| Key { key = "d" } \ (state.pending
|
||||||
| Some Delete \ applyOperator Delete WholeLine state
|
| Some Delete \ applyOperator Delete WholeLine state
|
||||||
| _ \ { state = state.{ pending = Some Delete }, emit = [] })
|
| _ \ { state = state.{ pending = Some Delete }, emit = [] })
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue