More vi motions

This commit is contained in:
Dustin Swan 2026-03-21 11:31:47 -06:00
parent 9fdbdf448f
commit a8e879289d
No known key found for this signature in database
GPG key ID: 30D46587E2100467

View file

@ -94,9 +94,18 @@ textEditor = name \
| 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 \ { row = from.row, col = 0, linewise = True } | WholeLine \ { row = from.row, col = 0, linewise = True }
| StartOfLine \ { row = from.row, col = 0 }
| StartOfLineChars \ nextWordStart state.lines from.row 0
| EndOfLine \ ( | EndOfLine \ (
line = nth state.cursorRow state.lines ~ unwrapOr ""; line = nth state.cursorRow state.lines ~ unwrapOr "";
{ row = state.cursorRow, col = (len line) - 1 }) { row = state.cursorRow, col = (len line) - 1 })
| FirstLine \ (
line = nth 0 state.lines ~ unwrapOr "";
{ row = 0, col = len line - 1 })
| LastLine \ (
lastRow = len state.lines - 1;
line = nth lastRow state.lines ~ unwrapOr "";
{ row = lastRow, col = len line - 1 })
| Cursor \ { row = state.cursorRow, col = state.cursorCol + 1 }; | Cursor \ { row = state.cursorRow, col = state.cursorCol + 1 };
{ from = from, to = to }; { from = from, to = to };
@ -326,14 +335,20 @@ textEditor = name \
| _ \ { state = state.{ pending = Some Delete }, emit = [] }) | _ \ { state = state.{ pending = Some Delete }, emit = [] })
| Key { key = "b" } \ handleMotion BackWord state | Key { key = "b" } \ handleMotion BackWord state
| Key { key = "w" } \ handleMotion Word state | Key { key = "w" } \ handleMotion Word state
| Key { key = "0" } \ handleMotion StartOfLine state
| Key { key = "^" } \ handleMotion StartOfLineChars state
| Key { key = "$" } \ handleMotion EndOfLine state | Key { key = "$" } \ handleMotion EndOfLine state
| Key { key = "g" } \ (state.pending
| Some "g" \ handleMotion FirstLine state.{ pending = None }
| _ \ { state = state.{ pending = Some "g" }, emit = [] })
| Key { key = "G" } \ handleMotion LastLine 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)
| Key { key = "W", ctrl = True, shift = True } \ write state | Key { key = "W", ctrl = True, shift = True } \ write state
| Key { key = "A", ctrl = True, shift = True } \ apply state | Key { key = "A", ctrl = True, shift = True } \ apply state
# any other key or event # any other key or event
| _ \ { state = state, emit = [] } | _ \ { state = state.{ pending = None }, emit = [] }
), ),
view = state emit \ view = state emit \