improvement in Cursor.getLineStartIdx when going to last line in buffer

This commit is contained in:
2024-11-04 02:46:02 +00:00
parent b368619df3
commit 66d4346c74
2 changed files with 24 additions and 24 deletions

View File

@@ -1707,27 +1707,27 @@ struct
(* Prerequisite: move lineGap to reqLine *) (* Prerequisite: move lineGap to reqLine *)
fun getLineStartIdx (lineGap: LineGap.t, reqLine) = fun getLineStartIdx (lineGap: LineGap.t, reqLine) =
let let
val {rightLines, line = bufferLine, idx = bufferIdx, ...} = lineGap val {rightStrings, rightLines, line = bufferLine, idx = bufferIdx, ...} = lineGap
in in
case rightLines of case (rightStrings, rightLines) of
hd :: tl => (shd :: stl, lhd :: ltl) =>
(* reqLine exists in lineGap, so retrieve it *) (* reqLine exists in lineGap, so retrieve it *)
let let
val relativeLine = reqLine - bufferLine - 1 val relativeLine = reqLine - bufferLine - 1
val lineIdx = Vector.sub (hd, relativeLine) val lineIdx = Vector.sub (lhd, relativeLine)
in in
if lineIdx = String.size shd - 1 andalso List.null stl then
(* if is end of buffer, return last idx in buffer; * else,
* increment by 1 as we want to go to first char after line break *)
bufferIdx + lineIdx
else
bufferIdx + lineIdx + 1 bufferIdx + lineIdx + 1
end end
| [] => | (_, _) =>
(* reqLine does not exist in lineGap, so just go to start of last line *) (* reqLine does not exist in lineGap, so just go to start of last line *)
let let
val {leftStrings, rightStrings, leftLines, ...} = lineGap val {leftStrings, leftLines, ...} = lineGap
in in
(case rightStrings of
hd :: _ =>
helpVi0
(~1, hd, bufferIdx - 1, leftStrings, leftLines)
| [] =>
(case (leftStrings, leftLines) of (case (leftStrings, leftLines) of
(lshd :: lstl, llhd :: lltl) => (lshd :: lstl, llhd :: lltl) =>
let let
@@ -1739,7 +1739,7 @@ struct
else else
result result
end end
| (_, _) => 0)) | (_, _) => 0)
end end
end end
end end

BIN
shf

Binary file not shown.