Drying up some code

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

View file

@ -266,6 +266,11 @@ textEditor = name \
newRow = state.cursorRow + diff;
withScroll { state = clampCursor state.{ cursorRow = newRow }, emit = [] });
handleMotion = motion state \
state.pending
| None \ withScroll { state = moveCursor (resolveMotion motion state) state, emit = [] }
| Some Delete \ withScroll (applyOperator Delete motion state);
ui.stateful {
focusable = True,
autoFocus = True,
@ -319,15 +324,9 @@ textEditor = name \
| Key { key = "d" } \ (state.pending
| Some Delete \ applyOperator Delete WholeLine state
| _ \ { state = state.{ pending = Some Delete }, emit = [] })
| Key { key = "b" } \ (state.pending
| None \ withScroll { state = moveCursor (resolveMotion BackWord state) state, emit = [] }
| Some Delete \ withScroll (applyOperator Delete BackWord state))
| 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 = "b" } \ handleMotion BackWord state
| Key { key = "w" } \ handleMotion Word state
| Key { key = "$" } \ handleMotion EndOfLine state
| Key { key = "." } \ (state.lastAction
| None \ { state = state, emit = [] }
| Some action \ applyOperator action.operator action.motion state)