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 *)
|
(* Prerequisite: move lineGap to reqLine *)
|
||||||
fun getLineStartIdx (lineGap: LineGap.t, reqLine) =
|
fun getLineStartIdx (lineGap: LineGap.t, reqLine) =
|
||||||
let
|
let
|
||||||
val {rightStrings, rightLines, line = bufferLine, idx = bufferIdx, ...} =
|
val
|
||||||
lineGap
|
{ rightStrings
|
||||||
|
, rightLines
|
||||||
|
, line = bufferLine
|
||||||
|
, idx = bufferIdx
|
||||||
|
, leftStrings
|
||||||
|
, leftLines
|
||||||
|
, ...
|
||||||
|
} = lineGap
|
||||||
in
|
in
|
||||||
case (rightStrings, rightLines) of
|
case (rightStrings, rightLines) of
|
||||||
(shd :: stl, lhd :: ltl) =>
|
(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
|
||||||
|
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)
|
val lineIdx = Vector.sub (lhd, relativeLine)
|
||||||
in
|
in
|
||||||
if lineIdx = String.size shd - 1 andalso List.null stl then
|
if lineIdx = String.size shd - 1 andalso List.null stl then
|
||||||
@@ -1142,6 +1165,7 @@ struct
|
|||||||
else
|
else
|
||||||
bufferIdx + lineIdx + 1
|
bufferIdx + lineIdx + 1
|
||||||
end
|
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
|
||||||
|
|||||||
@@ -192,7 +192,7 @@ struct
|
|||||||
* interpret as "go to line" command;
|
* interpret as "go to line" command;
|
||||||
* else, interpret as a command to move to end *)
|
* else, interpret as a command to move to end *)
|
||||||
if String.size str = 0 then NormalMove.moveToEnd app
|
if String.size str = 0 then NormalMove.moveToEnd app
|
||||||
else NormalMove.moveToLine (app, count - 1)
|
else NormalMove.moveToLine (app, count)
|
||||||
| #"%" => NormalMove.moveToMatchingPair app
|
| #"%" => NormalMove.moveToMatchingPair app
|
||||||
| #"x" => NormalDelete.removeChr (app, count, time)
|
| #"x" => NormalDelete.removeChr (app, count, time)
|
||||||
| #"J" => NormalDelete.removeLineBreaks (app, count, time)
|
| #"J" => NormalDelete.removeLineBreaks (app, count, time)
|
||||||
|
|||||||
@@ -107,6 +107,9 @@ struct
|
|||||||
end
|
end
|
||||||
|
|
||||||
fun moveToLine (app: app_type, reqLine) =
|
fun moveToLine (app: app_type, reqLine) =
|
||||||
|
let
|
||||||
|
val reqLine = reqLine - 1
|
||||||
|
in
|
||||||
if reqLine = 0 then
|
if reqLine = 0 then
|
||||||
moveToStart app
|
moveToStart app
|
||||||
else
|
else
|
||||||
@@ -166,6 +169,7 @@ struct
|
|||||||
, visualScrollColumn
|
, visualScrollColumn
|
||||||
)
|
)
|
||||||
end
|
end
|
||||||
|
end
|
||||||
|
|
||||||
fun moveToMatchingPair (app: app_type) =
|
fun moveToMatchingPair (app: app_type) =
|
||||||
let
|
let
|
||||||
|
|||||||
Reference in New Issue
Block a user