$ for end of line. cleaning up some stuff
This commit is contained in:
parent
d0e900a974
commit
7e6d79582f
1 changed files with 12 additions and 13 deletions
|
|
@ -93,19 +93,16 @@ textEditor = name \
|
|||
to = motion
|
||||
| Word \ nextWordStart state.lines from.row from.col
|
||||
| BackWord \ prevWordStart state.lines from.row from.col
|
||||
| WholeLine \ from
|
||||
| Cursor \ from;
|
||||
| WholeLine \ { row = from.row, col = 0, linewise = True }
|
||||
| EndOfLine \ (
|
||||
line = nth state.cursorRow state.lines ~ unwrapOr "";
|
||||
{ row = state.cursorRow, col = (len line) - 1 })
|
||||
| Cursor \ { row = state.cursorRow, col = state.cursorCol + 1 };
|
||||
{ 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 = [] } };
|
||||
{ state = state.{ lines = newLines }, emit = [] };
|
||||
|
||||
deleteRange = state from to \
|
||||
line = nth from.row state.lines ~ unwrapOr "";
|
||||
|
|
@ -119,10 +116,9 @@ textEditor = name \
|
|||
action = { operator = operator, motion = motion };
|
||||
stateSnapshot = { lines = state.lines, cursorRow = state.cursorRow, cursorCol = state.cursorCol };
|
||||
newState = operator
|
||||
| Delete \ (motion
|
||||
| WholeLine \ deleteLine state
|
||||
| Cursor \ deleteChar state
|
||||
| _ \ { state = deleteRange state target.from target.to, emit = [] });
|
||||
| Delete \ (hasField "linewise" target.to
|
||||
| True \ deleteLine state
|
||||
| False \ { state = deleteRange state target.from target.to, emit = [] });
|
||||
{ state = clampCursor newState.state.{ undoStack = [stateSnapshot, ...state.undoStack], pending = None, lastAction = Some action }, emit = newState.emit };
|
||||
|
||||
moveCursor = motion state \
|
||||
|
|
@ -329,6 +325,9 @@ textEditor = name \
|
|||
| Key { key = "w" } \ (state.pending
|
||||
| None \ withScroll { state = moveCursor (resolveMotion Word state) state, emit = [] }
|
||||
| Some Delete \ withScroll (applyOperator Delete Word state))
|
||||
| Key { key = "$" } \ (state.pending
|
||||
| None \ withScroll { state = moveCursor (resolveMotion EndOfLine state) state, emit = [] }
|
||||
| Some Delete \ withScroll (applyOperator Delete EndOfLine state))
|
||||
| Key { key = "." } \ (state.lastAction
|
||||
| None \ { state = state, emit = [] }
|
||||
| Some action \ applyOperator action.operator action.motion state)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue