$ 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
|
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 \ { row = from.row, col = 0, linewise = True }
|
||||||
| Cursor \ from;
|
| 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 };
|
{ 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 = [] };
|
||||||
|
|
||||||
deleteRange = state from to \
|
deleteRange = state from to \
|
||||||
line = nth from.row state.lines ~ unwrapOr "";
|
line = nth from.row state.lines ~ unwrapOr "";
|
||||||
|
|
@ -119,10 +116,9 @@ textEditor = name \
|
||||||
action = { operator = operator, motion = motion };
|
action = { operator = operator, motion = motion };
|
||||||
stateSnapshot = { lines = state.lines, cursorRow = state.cursorRow, cursorCol = state.cursorCol };
|
stateSnapshot = { lines = state.lines, cursorRow = state.cursorRow, cursorCol = state.cursorCol };
|
||||||
newState = operator
|
newState = operator
|
||||||
| Delete \ (motion
|
| Delete \ (hasField "linewise" target.to
|
||||||
| WholeLine \ deleteLine state
|
| True \ deleteLine state
|
||||||
| Cursor \ deleteChar state
|
| False \ { 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 };
|
||||||
|
|
||||||
moveCursor = motion state \
|
moveCursor = motion state \
|
||||||
|
|
@ -329,6 +325,9 @@ textEditor = name \
|
||||||
| Key { key = "w" } \ (state.pending
|
| Key { key = "w" } \ (state.pending
|
||||||
| None \ withScroll { state = moveCursor (resolveMotion Word state) state, emit = [] }
|
| None \ withScroll { state = moveCursor (resolveMotion Word state) state, emit = [] }
|
||||||
| Some Delete \ withScroll (applyOperator Delete Word state))
|
| 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
|
| Key { key = "." } \ (state.lastAction
|
||||||
| None \ { state = state, emit = [] }
|
| None \ { state = state, emit = [] }
|
||||||
| Some action \ applyOperator action.operator action.motion state)
|
| Some action \ applyOperator action.operator action.motion state)
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue