complete implementation of rightwards navigation (viL)

This commit is contained in:
2024-10-17 02:57:26 +01:00
parent 21652a5381
commit 428e5f2ecd
6 changed files with 43 additions and 15 deletions

30
fcore/cursor.sml Normal file
View File

@@ -0,0 +1,30 @@
structure Cursor =
struct
(* Prerequisite: lineGap is moved to requested idx first *)
fun viL (lineGap: LineGap.t, cursorIdx) =
let
val {rightStrings, idx = bufferIdx, ...} = lineGap
in
case rightStrings of
hd :: tl =>
let
(* idx relative to this string *)
val strIdx = cursorIdx - bufferIdx
in
if strIdx < String.size hd - 2 then
(* increment if there is a character after where cursor is *)
cursorIdx + 1
else
(case tl of
_ :: _ =>
(* if there is another string after current head, we can increment cursorIdx *)
bufferIdx + String.size hd - 1
| _ =>
(* if there is no string after current head, return original cursorIdx *)
cursorIdx)
end
| [] =>
(* return original cursorIdx if there is nothing to the right *)
cursorIdx
end
end