fix LineGap.goToLine bug: we weren't properly searching to check if the start of the searchLine was accessible in the node we stopped at

This commit is contained in:
2025-09-13 17:58:42 +01:00
parent 737e8695e7
commit 26862436d0

View File

@@ -2440,7 +2440,16 @@ struct
(idx, line, searchLine, leftStrings, leftLines, rightStrings, rightLines) = (idx, line, searchLine, leftStrings, leftLines, rightStrings, rightLines) =
case (leftStrings, leftLines) of case (leftStrings, leftLines) of
(lStrHd :: lStrTl, lLnHd :: lLnTl) => (lStrHd :: lStrTl, lLnHd :: lLnTl) =>
if searchLine < line - Vector.length lLnHd then if searchLine >= line - Vector.length lLnHd then
(* line is at left head, so place it to the right and return *)
{ idx = idx - String.size lStrHd
, line = line - Vector.length lLnHd
, leftStrings = lStrTl
, leftLines = lLnTl
, rightStrings = lStrHd :: rightStrings
, rightLines = lLnHd :: rightLines
}
else
(* move leftwards, joining if possible *) (* move leftwards, joining if possible *)
moveLeft moveLeft
( idx ( idx
@@ -2456,15 +2465,6 @@ struct
, lLnTl , lLnTl
, helpGoToLineLeft , helpGoToLineLeft
) )
else
(* line is at left head, so place it to the right and return *)
{ idx = idx - String.size lStrHd
, line = line - Vector.length lLnHd
, leftStrings = lStrTl
, leftLines = lLnTl
, rightStrings = lStrHd :: rightStrings
, rightLines = lLnHd :: rightLines
}
| (_, _) => | (_, _) =>
(* left side is empty, so just return *) (* left side is empty, so just return *)
{ idx = idx { idx = idx
@@ -2479,7 +2479,16 @@ struct
(idx, line, searchLine, leftStrings, leftLines, rightStrings, rightLines) = (idx, line, searchLine, leftStrings, leftLines, rightStrings, rightLines) =
case (rightStrings, rightLines) of case (rightStrings, rightLines) of
(rStrHd :: rStrTl, rLnHd :: rLnTl) => (rStrHd :: rStrTl, rLnHd :: rLnTl) =>
if searchLine > line + Vector.length rLnHd then if line + Vector.length rLnHd >= searchLine then
(* searchLine is in rStrHd/rLnHd, so return *)
{ idx = idx
, line = line
, leftStrings = leftStrings
, leftLines = leftLines
, rightStrings = rightStrings
, rightLines = rightLines
}
else
(* have to move rightwards *) (* have to move rightwards *)
moveRight moveRight
( idx ( idx
@@ -2495,15 +2504,6 @@ struct
, rLnTl , rLnTl
, helpGoToLineRight , helpGoToLineRight
) )
else
(* searchLine is in rStrHd/rLnHd, so return *)
{ idx = idx
, line = line
, leftStrings = leftStrings
, leftLines = leftLines
, rightStrings = rightStrings
, rightLines = rightLines
}
| (_, _) => | (_, _) =>
(* right side is empty, so just return *) (* right side is empty, so just return *)
{ idx = idx { idx = idx
@@ -2518,7 +2518,11 @@ struct
let let
val {idx, line, leftStrings, leftLines, rightStrings, rightLines} = buffer val {idx, line, leftStrings, leftLines, rightStrings, rightLines} = buffer
in in
if searchLine < line then (* we compare current line with searchLine - 1
* because if searchLine - 1 is here,
* that means we can access the linebreak
* that starts searchLine *)
if searchLine - 1 < line then
helpGoToLineLeft helpGoToLineLeft
( idx ( idx
, line , line
@@ -2528,7 +2532,7 @@ struct
, rightStrings , rightStrings
, rightLines , rightLines
) )
else if searchLine > line then else if searchLine - 1 > line then
helpGoToLineRight helpGoToLineRight
( idx ( idx
, line , line