fix 'Cursor.getLineStartIdx' function, which should look at the left nodes if there is no relevant line in this node
This commit is contained in:
@@ -1125,14 +1125,37 @@ struct
|
||||
(* Prerequisite: move lineGap to reqLine *)
|
||||
fun getLineStartIdx (lineGap: LineGap.t, reqLine) =
|
||||
let
|
||||
val {rightStrings, rightLines, line = bufferLine, idx = bufferIdx, ...} =
|
||||
lineGap
|
||||
val
|
||||
{ rightStrings
|
||||
, rightLines
|
||||
, line = bufferLine
|
||||
, idx = bufferIdx
|
||||
, leftStrings
|
||||
, leftLines
|
||||
, ...
|
||||
} = lineGap
|
||||
in
|
||||
case (rightStrings, rightLines) of
|
||||
(shd :: stl, lhd :: ltl) =>
|
||||
(* reqLine exists in lineGap, so retrieve it *)
|
||||
let
|
||||
val relativeLine = reqLine - bufferLine - 1
|
||||
in
|
||||
if relativeLine < 0 then
|
||||
(* line is in left node, if it exists *)
|
||||
(case (leftStrings, leftLines) of
|
||||
(leftShd :: leftStl, leftLhd :: leftLtl) =>
|
||||
startVi0
|
||||
( String.size leftShd - 1
|
||||
, leftShd
|
||||
, leftLhd
|
||||
, bufferIdx - 1
|
||||
, leftStl
|
||||
, leftLtl
|
||||
) + 1
|
||||
| (_, _) => 0)
|
||||
else
|
||||
let
|
||||
val lineIdx = Vector.sub (lhd, relativeLine)
|
||||
in
|
||||
if lineIdx = String.size shd - 1 andalso List.null stl then
|
||||
@@ -1142,6 +1165,7 @@ struct
|
||||
else
|
||||
bufferIdx + lineIdx + 1
|
||||
end
|
||||
end
|
||||
| (_, _) =>
|
||||
(* reqLine does not exist in lineGap, so just go to start of last line *)
|
||||
let
|
||||
|
||||
@@ -192,7 +192,7 @@ struct
|
||||
* interpret as "go to line" command;
|
||||
* else, interpret as a command to move to end *)
|
||||
if String.size str = 0 then NormalMove.moveToEnd app
|
||||
else NormalMove.moveToLine (app, count - 1)
|
||||
else NormalMove.moveToLine (app, count)
|
||||
| #"%" => NormalMove.moveToMatchingPair app
|
||||
| #"x" => NormalDelete.removeChr (app, count, time)
|
||||
| #"J" => NormalDelete.removeLineBreaks (app, count, time)
|
||||
|
||||
@@ -107,6 +107,9 @@ struct
|
||||
end
|
||||
|
||||
fun moveToLine (app: app_type, reqLine) =
|
||||
let
|
||||
val reqLine = reqLine - 1
|
||||
in
|
||||
if reqLine = 0 then
|
||||
moveToStart app
|
||||
else
|
||||
@@ -166,6 +169,7 @@ struct
|
||||
, visualScrollColumn
|
||||
)
|
||||
end
|
||||
end
|
||||
|
||||
fun moveToMatchingPair (app: app_type) =
|
||||
let
|
||||
|
||||
Reference in New Issue
Block a user