add function to go to first non-space character in line
This commit is contained in:
@@ -59,6 +59,30 @@ struct
|
||||
(newApp, drawMsg)
|
||||
end
|
||||
|
||||
fun firstNonSpaceChr (app: app_type) =
|
||||
let
|
||||
val {buffer, windowWidth, windowHeight, startLine, cursorIdx, ...} = app
|
||||
|
||||
(* move LineGap and buffer to start of line *)
|
||||
val buffer = LineGap.goToIdx (cursorIdx, buffer)
|
||||
val cursorIdx = Cursor.vi0 (buffer, cursorIdx)
|
||||
|
||||
(* move cursorIdx to first character on line *)
|
||||
val buffer = LineGap.goToIdx (cursorIdx, buffer)
|
||||
val cursorIdx = Cursor.firstNonSpaceChr (buffer, cursorIdx)
|
||||
|
||||
(* todo: get new startLine if cursor has moved out of screen *)
|
||||
|
||||
(* move LineGap to first line displayed on screen, and build new text *)
|
||||
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" => moveBackward (app, Cursor.viH)
|
||||
@@ -73,6 +97,7 @@ struct
|
||||
| #"B" => moveBackward (app, Cursor.prevWORD)
|
||||
| #"e" => moveFowrards (app, Cursor.endOfWord)
|
||||
| #"E" => moveFowrards (app, Cursor.endOfWORD)
|
||||
| #"^" => firstNonSpaceChr app
|
||||
| _ => (app, [])
|
||||
|
||||
fun update (app, msg) =
|
||||
|
||||
Reference in New Issue
Block a user