rewrite Cursor.viJ and Cursor.helpViJ for new line break scheme
This commit is contained in:
121
fcore/cursor.sml
121
fcore/cursor.sml
@@ -265,7 +265,7 @@ struct
|
|||||||
let
|
let
|
||||||
val strIdx = strIdx - String.size hd
|
val strIdx = strIdx - String.size hd
|
||||||
in
|
in
|
||||||
helpViH (strIdx, tllhd, cursorIdx, hd :: leftStrings)
|
helpViH (strIdx, tlhd, cursorIdx, hd :: leftStrings)
|
||||||
end
|
end
|
||||||
| [] => cursorIdx)
|
| [] => cursorIdx)
|
||||||
end
|
end
|
||||||
@@ -408,7 +408,7 @@ struct
|
|||||||
fun helpViJ
|
fun helpViJ
|
||||||
( strPos, str, absIdx
|
( strPos, str, absIdx
|
||||||
, lineColumn, preferredColumn, hasPassedLine
|
, lineColumn, preferredColumn, hasPassedLine
|
||||||
, strTl, lineTl
|
, strTl, lineTl, prevIsLn
|
||||||
) =
|
) =
|
||||||
if strPos = String.size str then
|
if strPos = String.size str then
|
||||||
case (strTl, lineTl) of
|
case (strTl, lineTl) of
|
||||||
@@ -422,7 +422,7 @@ struct
|
|||||||
helpViJ
|
helpViJ
|
||||||
( 0, shd, absIdx
|
( 0, shd, absIdx
|
||||||
, lineColumn, preferredColumn, hasPassedLine
|
, lineColumn, preferredColumn, hasPassedLine
|
||||||
, stl, ltl
|
, stl, ltl, prevIsLn
|
||||||
)
|
)
|
||||||
| (_, _) =>
|
| (_, _) =>
|
||||||
(* empty, so return end of previous string *)
|
(* empty, so return end of previous string *)
|
||||||
@@ -432,59 +432,22 @@ struct
|
|||||||
#"\n" =>
|
#"\n" =>
|
||||||
if hasPassedLine then
|
if hasPassedLine then
|
||||||
(* reached end of line twice,
|
(* reached end of line twice,
|
||||||
* but line has fewer chars than preferredColumn
|
* but line has fewer chars than preferredColumn *)
|
||||||
* note: if in double \n\n linebreak,
|
if prevIsLn then
|
||||||
* then return absIdx of second linebreak. *)
|
(* line break is preceded by linebreak *)
|
||||||
if strPos < String.size str - 1 then
|
absIdx
|
||||||
if String.sub (str, strPos + 1) = #"\n" then
|
|
||||||
(* we are in double linebreak *)
|
|
||||||
absIdx + 1
|
|
||||||
else
|
|
||||||
(* not in double linebreak *)
|
|
||||||
absIdx - 1
|
|
||||||
else
|
else
|
||||||
(* this is last chr of string; must check string's tl next *)
|
(* line break is preceded by graphical chr
|
||||||
(case strTl of
|
* so go to graphical chr *)
|
||||||
hd :: tl =>
|
absIdx - 1
|
||||||
if String.sub (hd, 0) = #"\n" then
|
|
||||||
(* in double linebreak *)
|
|
||||||
absIdx + 1
|
|
||||||
else
|
|
||||||
(* not in double linebreak *)
|
|
||||||
absIdx - 1
|
|
||||||
| [] =>
|
|
||||||
(* no more strings so return last idx *)
|
|
||||||
absIdx - 1)
|
|
||||||
else
|
else
|
||||||
(* reached end of line once;
|
(* reached end of line once;
|
||||||
* have to check if this is a double linebreak,
|
* continue iterationg *)
|
||||||
* and return idx of second linebreak if so *)
|
helpViJ
|
||||||
if strPos < String.size str - 1 then
|
( strPos + 1, str, absIdx + 1
|
||||||
if String.sub (str, strPos + 1) = #"\n" then
|
, 0, preferredColumn, true
|
||||||
absIdx + 1
|
, strTl, lineTl, true
|
||||||
else
|
)
|
||||||
helpViJ
|
|
||||||
( strPos + 1, str, absIdx + 1
|
|
||||||
, 0, preferredColumn, true
|
|
||||||
, strTl, lineTl
|
|
||||||
)
|
|
||||||
else
|
|
||||||
(* this is last chr of string; must check string's tl next *)
|
|
||||||
(case strTl of
|
|
||||||
hd :: tl =>
|
|
||||||
if String.sub (hd, 0) = #"\n" then
|
|
||||||
(* in double linebreak *)
|
|
||||||
absIdx + 1
|
|
||||||
else
|
|
||||||
(* not in double linebreak *)
|
|
||||||
helpViJ
|
|
||||||
( strPos + 1, str, absIdx + 1
|
|
||||||
, 0, preferredColumn, true
|
|
||||||
, strTl, lineTl
|
|
||||||
)
|
|
||||||
| [] =>
|
|
||||||
(* no more strings so return last idx *)
|
|
||||||
absIdx)
|
|
||||||
| _ =>
|
| _ =>
|
||||||
if lineColumn = preferredColumn andalso hasPassedLine then
|
if lineColumn = preferredColumn andalso hasPassedLine then
|
||||||
(* we're at the preferredColumn so return absIdx *)
|
(* we're at the preferredColumn so return absIdx *)
|
||||||
@@ -494,7 +457,7 @@ struct
|
|||||||
helpViJ
|
helpViJ
|
||||||
( strPos + 1, str, absIdx + 1
|
( strPos + 1, str, absIdx + 1
|
||||||
, lineColumn + 1, preferredColumn, hasPassedLine
|
, lineColumn + 1, preferredColumn, hasPassedLine
|
||||||
, strTl, lineTl
|
, strTl, lineTl, false
|
||||||
)
|
)
|
||||||
|
|
||||||
fun viJ (lineGap: LineGap.t, cursorIdx) =
|
fun viJ (lineGap: LineGap.t, cursorIdx) =
|
||||||
@@ -508,31 +471,15 @@ struct
|
|||||||
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
|
||||||
|
val lineColumn = getCursorColumn (lineGap, cursorIdx)
|
||||||
in
|
in
|
||||||
if strIdx < String.size strHd then
|
if strIdx < String.size strHd then
|
||||||
(* strIdx is in this string *)
|
(* strIdx is in this string *)
|
||||||
if String.sub (strHd, strIdx) = #"\n" then
|
helpViJ
|
||||||
(* if we are at a newline
|
( strIdx, strHd, cursorIdx
|
||||||
* note:
|
, lineColumn, lineColumn, false
|
||||||
* don't need to check if we are a double linebreak,
|
, strTl, lnTl, false
|
||||||
* because cursor navigation functions already check
|
)
|
||||||
* for that condition at the end.
|
|
||||||
* So there is no way at the start of a navigation function
|
|
||||||
* that cursor is in a double linebreak incorrectly. *)
|
|
||||||
helpViJ
|
|
||||||
(strIdx + 1, strHd, cursorIdx + 1, 0, 0, true, strTl, lnTl)
|
|
||||||
else
|
|
||||||
(* not at newline
|
|
||||||
* so get column number and start iterating *)
|
|
||||||
let
|
|
||||||
val lineColumn = getCursorColumn (lineGap, cursorIdx)
|
|
||||||
in
|
|
||||||
helpViJ
|
|
||||||
( strIdx + 1, strHd, cursorIdx + 1
|
|
||||||
, lineColumn, lineColumn, false
|
|
||||||
, strTl, lnTl
|
|
||||||
)
|
|
||||||
end
|
|
||||||
else
|
else
|
||||||
(* strIdx must be in the strTl *)
|
(* strIdx must be in the strTl *)
|
||||||
(case (strTl, lnTl) of
|
(case (strTl, lnTl) of
|
||||||
@@ -540,23 +487,11 @@ struct
|
|||||||
let
|
let
|
||||||
val strIdx = strIdx - String.size strHd
|
val strIdx = strIdx - String.size strHd
|
||||||
in
|
in
|
||||||
if String.sub (nestStrHd, strIdx) = #"\n" then
|
helpViJ
|
||||||
helpViJ
|
( strIdx, nestStrHd, cursorIdx
|
||||||
( strIdx + 1, nestStrHd, cursorIdx + 1
|
, lineColumn, lineColumn, false
|
||||||
, 0, 0, true
|
, nestStrTl, nestLnTl, false
|
||||||
, nestStrTl, nestLnTl
|
)
|
||||||
)
|
|
||||||
else
|
|
||||||
(* not in linebreak *)
|
|
||||||
let
|
|
||||||
val lineColumn = getCursorColumn (lineGap, cursorIdx)
|
|
||||||
in
|
|
||||||
helpViJ
|
|
||||||
( strIdx + 1, nestStrHd, cursorIdx + 1
|
|
||||||
, lineColumn, lineColumn, false
|
|
||||||
, nestStrTl, nestLnTl
|
|
||||||
)
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
| (_, _) => cursorIdx)
|
| (_, _) => cursorIdx)
|
||||||
end
|
end
|
||||||
|
|||||||
Reference in New Issue
Block a user