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,39 +1707,39 @@ 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
bufferIdx + lineIdx + 1 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
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 (case (leftStrings, leftLines) of
hd :: _ => (lshd :: lstl, llhd :: lltl) =>
helpVi0 let
(~1, hd, bufferIdx - 1, leftStrings, leftLines) val result = helpVi0
| [] => (String.size lshd - 1, lshd, bufferIdx - 1, lstl, lltl)
(case (leftStrings, leftLines) of in
(lshd :: lstl, llhd :: lltl) => if result = bufferIdx then
let bufferIdx - 1
val result = helpVi0 else
(String.size lshd - 1, lshd, bufferIdx - 1, lstl, lltl) result
in end
if result = bufferIdx then | (_, _) => 0)
bufferIdx - 1
else
result
end
| (_, _) => 0))
end end
end end
end end

BIN
shf

Binary file not shown.