in NormalMove.moveToLine function, use new LineGap function, 'LineGap.lineNumberToIdx', to get the index a line is at, and delete the Cursor.getLineStartIdx' function which we no longer need, as that functionality is in brolib-sml itself.
This commit is contained in:
@@ -1003,73 +1003,6 @@ struct
|
||||
| [] => cursorIdx
|
||||
end
|
||||
|
||||
(* Prerequisite: move lineGap to reqLine *)
|
||||
fun getLineStartIdx (lineGap: LineGap.t, reqLine) =
|
||||
let
|
||||
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
|
||||
(* 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
|
||||
end
|
||||
end
|
||||
| (_, _) =>
|
||||
(* reqLine does not exist in lineGap, so just go to start of last line *)
|
||||
let
|
||||
val {leftStrings, leftLines, ...} = lineGap
|
||||
in
|
||||
(case (leftStrings, leftLines) of
|
||||
(lshd :: lstl, llhd :: lltl) =>
|
||||
let
|
||||
val result = startVi0
|
||||
( String.size lshd - 1
|
||||
, lshd
|
||||
, llhd
|
||||
, bufferIdx - 1
|
||||
, lstl
|
||||
, lltl
|
||||
)
|
||||
in
|
||||
if result = bufferIdx then bufferIdx - 1 else result
|
||||
end
|
||||
| (_, _) => 0)
|
||||
end
|
||||
end
|
||||
|
||||
(* Prerequisite: lineGap is moved to cursorIdx *)
|
||||
fun isCursorAtStartOfLine (lineGap: LineGap.t, cursorIdx) =
|
||||
let
|
||||
|
||||
@@ -128,7 +128,7 @@ struct
|
||||
val buffer = LineGap.goToLine (reqLine, buffer)
|
||||
|
||||
(* get idx of first chr after linebreak *)
|
||||
val cursorIdx = Cursor.getLineStartIdx (buffer, reqLine)
|
||||
val cursorIdx = LineGap.lineNumberToIdx (reqLine, buffer)
|
||||
val buffer = LineGap.goToIdx (cursorIdx, buffer)
|
||||
|
||||
(* we got the line start idx, but we want to move to the index
|
||||
|
||||
Reference in New Issue
Block a user