reimplement vi's 'j' motion, and remove the original function for this motion which was in cursor.sml
This commit is contained in:
141
fcore/cursor.sml
141
fcore/cursor.sml
@@ -132,147 +132,6 @@ struct
|
||||
if lineIdx = 0 then cursorIdx else cursorIdx - lineIdx - 1
|
||||
end
|
||||
|
||||
fun helpViJ
|
||||
( strPos
|
||||
, str
|
||||
, absIdx
|
||||
, lineColumn
|
||||
, preferredColumn
|
||||
, hasPassedLine
|
||||
, strTl
|
||||
, lineTl
|
||||
, prevIsLn
|
||||
) =
|
||||
if strPos = String.size str then
|
||||
case (strTl, lineTl) of
|
||||
(shd :: stl, lhd :: ltl) =>
|
||||
(* todo: possibly check if we have passed line,
|
||||
* and if so, if there are any line breaks in the lineHd
|
||||
* which we could use to skip searching part of the string.
|
||||
* However, this will likely have worse cache locality
|
||||
* as we switch to searching in string to searcing in line vector
|
||||
* so perhaps not. *)
|
||||
helpViJ
|
||||
( 0
|
||||
, shd
|
||||
, absIdx
|
||||
, lineColumn
|
||||
, preferredColumn
|
||||
, hasPassedLine
|
||||
, stl
|
||||
, ltl
|
||||
, prevIsLn
|
||||
)
|
||||
| (_, _) => (* empty, so return end of previous string *) absIdx - 1
|
||||
else
|
||||
case String.sub (str, strPos) of
|
||||
#"\n" =>
|
||||
if hasPassedLine then
|
||||
(* reached end of line twice,
|
||||
* but line has fewer chars than preferredColumn *)
|
||||
if prevIsLn then
|
||||
(* line break is preceded by linebreak *)
|
||||
absIdx
|
||||
else
|
||||
(* line break is preceded by graphical chr
|
||||
* so go to graphical chr *)
|
||||
absIdx - 1
|
||||
else
|
||||
(* reached end of line once;
|
||||
* continue iterationg *)
|
||||
helpViJ
|
||||
( strPos + 1
|
||||
, str
|
||||
, absIdx + 1
|
||||
, 0
|
||||
, preferredColumn
|
||||
, true
|
||||
, strTl
|
||||
, lineTl
|
||||
, true
|
||||
)
|
||||
| _ =>
|
||||
if lineColumn = preferredColumn andalso hasPassedLine then
|
||||
(* we're at the preferredColumn so return absIdx *)
|
||||
absIdx
|
||||
else
|
||||
(* we're not in the preferred column, so keep iterating *)
|
||||
helpViJ
|
||||
( strPos + 1
|
||||
, str
|
||||
, absIdx + 1
|
||||
, lineColumn + 1
|
||||
, preferredColumn
|
||||
, hasPassedLine
|
||||
, strTl
|
||||
, lineTl
|
||||
, false
|
||||
)
|
||||
|
||||
fun viJ (lineGap: LineGap.t, cursorIdx) =
|
||||
let
|
||||
val
|
||||
{rightStrings, idx = bufferIdx, rightLines, leftStrings, leftLines, ...} =
|
||||
lineGap
|
||||
in
|
||||
case (rightStrings, rightLines) of
|
||||
(strHd :: strTl, lnHd :: lnTl) =>
|
||||
let
|
||||
(* convert absolute cursorIdx to idx relative to hd string *)
|
||||
val strIdx = cursorIdx - bufferIdx
|
||||
in
|
||||
if strIdx < String.size strHd then
|
||||
(* strIdx is in this string *)
|
||||
let
|
||||
val lineColumn = getCursorColumn
|
||||
(strIdx, strHd, lnHd, leftStrings, leftLines, cursorIdx)
|
||||
in
|
||||
helpViJ
|
||||
( strIdx
|
||||
, strHd
|
||||
, cursorIdx
|
||||
, lineColumn
|
||||
, lineColumn
|
||||
, false
|
||||
, strTl
|
||||
, lnTl
|
||||
, false
|
||||
)
|
||||
end
|
||||
else
|
||||
(* strIdx must be in the strTl *)
|
||||
(case (strTl, lnTl) of
|
||||
(nestStrHd :: nestStrTl, nestLnHd :: nestLnTl) =>
|
||||
let
|
||||
val strIdx = strIdx - String.size strHd
|
||||
val leftStrings = strHd :: leftStrings
|
||||
val leftLines = lnHd :: leftLines
|
||||
val lineColumn = getCursorColumn
|
||||
( strIdx
|
||||
, nestStrHd
|
||||
, nestLnHd
|
||||
, leftStrings
|
||||
, leftLines
|
||||
, cursorIdx
|
||||
)
|
||||
in
|
||||
helpViJ
|
||||
( strIdx
|
||||
, nestStrHd
|
||||
, cursorIdx
|
||||
, lineColumn
|
||||
, lineColumn
|
||||
, false
|
||||
, nestStrTl
|
||||
, nestLnTl
|
||||
, false
|
||||
)
|
||||
end
|
||||
| (_, _) => cursorIdx)
|
||||
end
|
||||
| (_, _) => (* nowhere to go rightward, so return cursorIdx *) cursorIdx
|
||||
end
|
||||
|
||||
(* equivalent of vi's 'w' command *)
|
||||
val nextWord = ViWordDfa.startOfNextWord
|
||||
|
||||
|
||||
Reference in New Issue
Block a user