implement vi0 and viDlr (viDlr = function called when pressing $), which both work fine

This commit is contained in:
2024-10-21 03:04:47 +01:00
parent e08f2c4f77
commit b22222cf5d
3 changed files with 180 additions and 0 deletions

View File

@@ -85,12 +85,46 @@ struct
(newApp, drawMsg)
end
fun moveToLineStart (app: app_type) =
let
val {buffer, windowWidth, windowHeight, startLine, cursorIdx, ...} = app
val buffer = LineGap.goToIdx (cursorIdx, buffer)
val cursorIdx = Cursor.vi0 (buffer, cursorIdx)
val buffer = LineGap.goToLine (startLine, buffer)
val drawMsg = TextBuilder.build
(startLine, cursorIdx, buffer, windowWidth, windowHeight)
val newApp = AppWith.bufferAndCursorIdx (app, buffer, cursorIdx)
in
(newApp, drawMsg)
end
fun moveToLineEnd (app: app_type) =
let
val {buffer, windowWidth, windowHeight, startLine, cursorIdx, ...} = app
val buffer = LineGap.goToIdx (cursorIdx, buffer)
val cursorIdx = Cursor.viDlr (buffer, cursorIdx)
val buffer = LineGap.goToLine (startLine, buffer)
val drawMsg = TextBuilder.build
(startLine, cursorIdx, buffer, windowWidth, windowHeight)
val newApp = AppWith.bufferAndCursorIdx (app, buffer, cursorIdx)
in
(newApp, drawMsg)
end
fun handleChr (app: app_type, chr) =
case chr of
#"h" => moveLeft app
| #"j" => moveDown app
| #"k" => moveUp app
| #"l" => moveRight app
| #"0" => moveToLineStart app
| #"$" => moveToLineEnd app
| _ => (app, [])
fun update (app, msg) =