simplify viK and especially startViK in cursor.sml, by only checking (strIdx - 1) and (strIdx - 2)
This commit is contained in:
@@ -559,34 +559,14 @@ struct
|
|||||||
|
|
||||||
fun startViK (lg, strIdx, shd, cursorIdx, leftStrings, lhd, leftLines) =
|
fun startViK (lg, strIdx, shd, cursorIdx, leftStrings, lhd, leftLines) =
|
||||||
if String.sub (shd, strIdx) = #"\n" then
|
if String.sub (shd, strIdx) = #"\n" then
|
||||||
|
(* ? -> \n *)
|
||||||
if strIdx > 0 then
|
if strIdx > 0 then
|
||||||
(* strIdx - 1 is in shd *)
|
(* strIdx - 1 is in shd *)
|
||||||
if String.sub (shd, strIdx - 1) = #"\n" then
|
if String.sub (shd, strIdx - 1) = #"\n" then
|
||||||
(* strIdx - 1 is \n *)
|
|
||||||
if strIdx - 1 > 0 then
|
|
||||||
(* strIdx - 2 is in shd *)
|
|
||||||
if String.sub (shd, strIdx - 2) = #"\n" then
|
|
||||||
(* \n -> \n *)
|
(* \n -> \n *)
|
||||||
cursorIdx - 1
|
cursorIdx
|
||||||
else
|
else
|
||||||
(* graphical-chr -> \n *)
|
(* non-graphical-chr -> \n *)
|
||||||
helpVi0
|
|
||||||
(strIdx - 2, shd, cursorIdx - 2, leftStrings, leftLines)
|
|
||||||
else
|
|
||||||
(* strIdx - 2 is in leftStrings *)
|
|
||||||
case (leftStrings, leftLines) of
|
|
||||||
(lshd :: lstl, llhd :: lltl) =>
|
|
||||||
if String.sub (lshd, String.size lshd - 1) = #"\n" then
|
|
||||||
(* \n -> \n *)
|
|
||||||
cursorIdx - 1
|
|
||||||
else
|
|
||||||
(* graphical-chr -> \n *)
|
|
||||||
helpVi0
|
|
||||||
(String.size lshd - 2, lshd, cursorIdx - 2, lstl, lltl)
|
|
||||||
| (_, _) =>
|
|
||||||
cursorIdx - 1
|
|
||||||
else
|
|
||||||
(* strIdx - 1 is not \n *)
|
|
||||||
let
|
let
|
||||||
val lineColumn = getCursorColumn (lg, cursorIdx)
|
val lineColumn = getCursorColumn (lg, cursorIdx)
|
||||||
in
|
in
|
||||||
@@ -601,49 +581,18 @@ struct
|
|||||||
case (leftStrings, leftLines) of
|
case (leftStrings, leftLines) of
|
||||||
(lshd :: lstl, llhd :: lltl) =>
|
(lshd :: lstl, llhd :: lltl) =>
|
||||||
if String.sub (lshd, String.size lshd - 1) = #"\n" then
|
if String.sub (lshd, String.size lshd - 1) = #"\n" then
|
||||||
(* ? -> \n *)
|
|
||||||
if String.size lshd > 1 then
|
|
||||||
(* if strIdx - 2 is in lshd *)
|
|
||||||
if String.sub (lshd, String.size lshd - 2) = #"\n" then
|
|
||||||
(* \n -> \n *)
|
(* \n -> \n *)
|
||||||
cursorIdx - 1
|
cursorIdx
|
||||||
else
|
else
|
||||||
(* graphical-chr -> \n *)
|
(* graphical-chr -> \n *)
|
||||||
helpVi0
|
helpVi0
|
||||||
(String.size lshd - 2, lshd, cursorIdx - 2, lstl, lltl)
|
(String.size lshd - 2, lshd, cursorIdx - 2, lstl, lltl)
|
||||||
else
|
|
||||||
(* strIdx - 2 is in lstl *)
|
|
||||||
(case (lstl, lltl) of
|
|
||||||
(stlhd :: stltl, ltlhd :: ltltl) =>
|
|
||||||
if String.sub (stlhd, String.size stlhd - 1) = #"\n" then
|
|
||||||
(* \n -> \n *)
|
|
||||||
cursorIdx - 1
|
|
||||||
else
|
|
||||||
(* graphical-chr -> \n *)
|
|
||||||
helpVi0
|
|
||||||
( String.size stlhd - 2, stlhd
|
|
||||||
, cursorIdx - 2, stltl, ltltl
|
|
||||||
)
|
|
||||||
| (_, _) =>
|
|
||||||
cursorIdx - 1)
|
|
||||||
else
|
|
||||||
(* does not start with \n
|
|
||||||
* so start viK normally *)
|
|
||||||
let
|
|
||||||
val lineColumn = getCursorColumn (lg, cursorIdx)
|
|
||||||
in
|
|
||||||
helpViK
|
|
||||||
( strIdx, shd, cursorIdx
|
|
||||||
, lineColumn, lineColumn, false
|
|
||||||
, leftStrings, lhd, leftLines
|
|
||||||
)
|
|
||||||
end
|
|
||||||
| (_, _) => cursorIdx
|
| (_, _) => cursorIdx
|
||||||
else
|
else
|
||||||
(* strIdx does not start with \n
|
(* strIdx does not start with \n
|
||||||
* so start viK normally*)
|
* so start viK normally*)
|
||||||
let
|
let
|
||||||
val lineColumn = getCursorColumn (lg, cursorIdx)
|
val lineColumn = getCursorColumn (lg, cursorIdx) + 1
|
||||||
in
|
in
|
||||||
helpViK
|
helpViK
|
||||||
( strIdx, shd, cursorIdx
|
( strIdx, shd, cursorIdx
|
||||||
@@ -659,30 +608,13 @@ struct
|
|||||||
lineGap
|
lineGap
|
||||||
in
|
in
|
||||||
case (rightStrings, rightLines) of
|
case (rightStrings, rightLines) of
|
||||||
(strHd :: strTl, lnHd :: lnTl) =>
|
(strHd :: _, lnHd :: _) =>
|
||||||
let
|
let
|
||||||
(* convert absolute cursorIdx to idx relative to hd string *)
|
(* convert absolute cursorIdx to idx relative to hd string *)
|
||||||
val strIdx = cursorIdx - bufferIdx
|
val strIdx = cursorIdx - bufferIdx
|
||||||
in
|
in
|
||||||
if strIdx < String.size strHd then
|
|
||||||
(* strIdx is in this string *)
|
|
||||||
startViK
|
startViK
|
||||||
(lineGap, strIdx, strHd, cursorIdx, leftStrings, lnHd, leftLines)
|
(lineGap, strIdx - 1, strHd, cursorIdx - 1, leftStrings, lnHd, leftLines)
|
||||||
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
|
|
||||||
in
|
|
||||||
startViK
|
|
||||||
( lineGap, strIdx, nestStrHd, cursorIdx
|
|
||||||
, leftStrings, nestLnHd, leftLines
|
|
||||||
)
|
|
||||||
end
|
|
||||||
| (_, _) => cursorIdx)
|
|
||||||
end
|
end
|
||||||
| (_, _) =>
|
| (_, _) =>
|
||||||
(* nowhere to go rightward, so return cursorIdx *)
|
(* nowhere to go rightward, so return cursorIdx *)
|
||||||
|
|||||||
Reference in New Issue
Block a user