progress functorising
This commit is contained in:
@@ -863,12 +863,16 @@ struct
|
||||
|
||||
val toPrevChr = ToPrevChr.foldPrev
|
||||
|
||||
structure TillPrevChr =
|
||||
MakeIfCharFolderPrev
|
||||
(struct
|
||||
type env = char
|
||||
|
||||
fun helpTillPrevChr
|
||||
( strPos
|
||||
, str
|
||||
, absIdx
|
||||
, stl
|
||||
, ltl
|
||||
, origIdx
|
||||
, findChr
|
||||
, lastNonLine
|
||||
@@ -876,21 +880,20 @@ struct
|
||||
, lastValid
|
||||
) =
|
||||
if strPos < 0 then
|
||||
case (stl, ltl) of
|
||||
(shd :: stl, lhd :: ltl) =>
|
||||
case stl of
|
||||
shd :: stl =>
|
||||
helpTillPrevChr
|
||||
( String.size shd - 1
|
||||
, shd
|
||||
, absIdx
|
||||
, stl
|
||||
, ltl
|
||||
, origIdx
|
||||
, findChr
|
||||
, lastNonLine
|
||||
, lastLine
|
||||
, lastValid
|
||||
)
|
||||
| (_, _) => origIdx
|
||||
| [] => origIdx
|
||||
else
|
||||
let
|
||||
val chr = String.sub (str, strPos)
|
||||
@@ -927,7 +930,6 @@ struct
|
||||
, str
|
||||
, absIdx - 1
|
||||
, stl
|
||||
, ltl
|
||||
, origIdx
|
||||
, findChr
|
||||
, lastNonLine
|
||||
@@ -937,7 +939,7 @@ struct
|
||||
end
|
||||
end
|
||||
|
||||
fun startTillPrevChr (shd, strIdx, absIdx, stl, ltl, findChr) =
|
||||
fun fStart (strIdx, shd, _, absIdx, stl, ltl, findChr) =
|
||||
(* we want to start iterating from Prev char after strIdx *)
|
||||
if strIdx > 0 then
|
||||
helpTillPrevChr
|
||||
@@ -945,7 +947,6 @@ struct
|
||||
, shd
|
||||
, absIdx - 1
|
||||
, stl
|
||||
, ltl
|
||||
, absIdx
|
||||
, findChr
|
||||
, absIdx
|
||||
@@ -953,56 +954,23 @@ struct
|
||||
, absIdx
|
||||
)
|
||||
else
|
||||
case (stl, ltl) of
|
||||
(stlhd :: stltl, ltlhd :: ltltl) =>
|
||||
case stl of
|
||||
stlhd :: stltl =>
|
||||
helpTillPrevChr
|
||||
( String.size stlhd - 1
|
||||
, stlhd
|
||||
, absIdx - 1
|
||||
, stltl
|
||||
, ltltl
|
||||
, absIdx
|
||||
, findChr
|
||||
, absIdx
|
||||
, absIdx
|
||||
, absIdx
|
||||
)
|
||||
| (_, _) => (* tl is empty; return 0 for lineGap start *) 0
|
||||
| [] => (* tl is empty; return 0 for lineGap start *) 0
|
||||
end)
|
||||
|
||||
fun prevChr (lineGap: LineGap.t, cursorIdx, chr, fStart) =
|
||||
let
|
||||
val
|
||||
{rightStrings, rightLines, idx = bufferIdx, leftStrings, leftLines, ...} =
|
||||
lineGap
|
||||
in
|
||||
case (rightStrings, rightLines) of
|
||||
(shd :: stl, lhd :: ltl) =>
|
||||
let
|
||||
(* convert absolute cursorIdx to idx relative to hd string *)
|
||||
val strIdx = cursorIdx - bufferIdx
|
||||
in
|
||||
if strIdx < String.size shd then
|
||||
(* strIdx is in this string *)
|
||||
fStart (shd, strIdx, cursorIdx, leftStrings, leftLines, chr)
|
||||
else
|
||||
(* strIdx is in tl *)
|
||||
(case (stl, ltl) of
|
||||
(stlhd :: stltl, ltlhd :: ltltl) =>
|
||||
let
|
||||
val strIdx = strIdx - String.size shd
|
||||
val leftStrings = shd :: leftStrings
|
||||
val leftLines = lhd :: leftLines
|
||||
in
|
||||
fStart
|
||||
(shd, strIdx, cursorIdx, leftStrings, leftLines, chr)
|
||||
end
|
||||
| (_, _) => cursorIdx)
|
||||
end
|
||||
| (_, _) => cursorIdx
|
||||
end
|
||||
|
||||
fun tillPrevChr (lineGap, cursorIdx, chr) =
|
||||
prevChr (lineGap, cursorIdx, chr, startTillPrevChr)
|
||||
val tillPrevChr = TillPrevChr.foldPrev
|
||||
|
||||
fun helpMatchPairNext
|
||||
(strPos, str, absIdx, stl, origIdx, openChr, openNum, closeChr, closeNum) =
|
||||
|
||||
Reference in New Issue
Block a user