texteditor: replaceChar
This commit is contained in:
parent
fcb8feb16f
commit
88098a9ce0
1 changed files with 16 additions and 1 deletions
|
|
@ -1,7 +1,7 @@
|
|||
@textEditor
|
||||
|
||||
_ = "TODO
|
||||
# r to repalce
|
||||
# R to replace instead of insert
|
||||
# s to seek
|
||||
# w / b bug, can't select `textEditor` at start of line
|
||||
# smart case searching
|
||||
|
|
@ -161,6 +161,17 @@ textEditor = name \
|
|||
|
||||
{ state = state.{ lines = newLines, cursorCol = state.cursorCol + 1 }, emit = [] };
|
||||
|
||||
replaceChar = char state \
|
||||
newLines = updateAt state.cursorRow (line \
|
||||
newLine = deleteCharAt line state.cursorCol;
|
||||
insertCharAt newLine state.cursorCol char
|
||||
) state.lines;
|
||||
|
||||
stateSnapshot = { lines = state.lines, cursorRow = state.cursorRow, cursorCol = state.cursorCol };
|
||||
newUndoStack = [stateSnapshot, ...state.undoStack];
|
||||
|
||||
{ state = state.{ lines = newLines, mode = Normal, undoStack = newUndoStack }, emit = [] };
|
||||
|
||||
insertMode = state \
|
||||
stateSnapshot = { lines = state.lines, cursorRow = state.cursorRow, cursorCol = state.cursorCol };
|
||||
newUndoStack = [stateSnapshot, ...state.undoStack];
|
||||
|
|
@ -424,6 +435,9 @@ textEditor = name \
|
|||
| Key { key = "Enter" } \ enter state
|
||||
| Key { key = k, printable = True } \ insertChar k state
|
||||
| _ \ { state = state , emit = [] })
|
||||
| ReplaceChar \ (event
|
||||
| Key { key = k, printable = True } \ replaceChar k state
|
||||
| _ \ { state = state.{ mode = Normal }, emit = [] })
|
||||
| Normal \ (event
|
||||
| Scrolled delta \ (
|
||||
maxLineLen = fold (acc line \ max acc (len line)) 0 state.lines;
|
||||
|
|
@ -450,6 +464,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 = "r" } \ { state = state.{ mode = ReplaceChar }, emit = [] }
|
||||
| Key { key = "x" } \ applyOperator Delete Cursor state
|
||||
| Key { key = "d" } \ (state.pending
|
||||
| Some Delete \ applyOperator Delete WholeLine state
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue