address edge case when '0' is input, because '0' may either be a count if some number preceded it, or else it is a command to go the start of the line

This commit is contained in:
2024-10-26 11:04:04 +01:00
parent 62a9aaaaab
commit eeacde8e7a
2 changed files with 27 additions and 2 deletions

View File

@@ -137,8 +137,33 @@ struct
| #"B" => moveBackward (app, count, Cursor.prevWORD)
| #"e" => moveForwards (app, count, Cursor.endOfWord)
| #"E" => moveForwards (app, count, Cursor.endOfWORD)
(* can only move to start or end of line once *)
| #"0" => moveBackward (app, 1, Cursor.vi0)
(* can only move to start or end of line once
* so hardcode count as 1 *)
| #"0" =>
(* 0 is a bit of a special case.
* If 0 is pressed without any preceding characters,
* then it should move cursor to the start of the line.
* However, if a number was pressed previously before 0 was,
* then this means user is entering a count.
* In that case, we append 0 to the string. *)
if String.size str > 0 then
let
val lastChr = String.sub (str, String.size str - 1)
in
if Char.isDigit lastChr then
let
val chr = Char.toString chr
val str = str ^ chr
val mode = NORMAL_MODE str
val newApp = AppWith.mode (app, mode)
in
(newApp, [])
end
else
moveBackward (app, 1, Cursor.vi0)
end
else
moveBackward (app, 1, Cursor.vi0)
| #"$" => moveForwards (app, 1, Cursor.viDlr)
| #"^" => firstNonSpaceChr app
(* multi-char commands which can be appended *)

BIN
shf

Binary file not shown.