fix bug with tillNextChr which would place cursor on a newline
This commit is contained in:
110
fcore/cursor.sml
110
fcore/cursor.sml
@@ -1263,36 +1263,36 @@ struct
|
|||||||
cursorIdx
|
cursorIdx
|
||||||
end
|
end
|
||||||
|
|
||||||
fun helpNextChr (strPos, str, absIdx, stl, ltl, origIdx, findChr, fResult) =
|
fun helpToNextChr (strPos, str, absIdx, stl, ltl, origIdx, findChr) =
|
||||||
if strPos = String.size str then
|
if strPos = String.size str then
|
||||||
case (stl, ltl) of
|
case (stl, ltl) of
|
||||||
(shd :: stl, lhd :: ltl) =>
|
(shd :: stl, lhd :: ltl) =>
|
||||||
helpNextChr
|
helpToNextChr
|
||||||
(0, shd, absIdx, stl, ltl, origIdx, findChr, fResult)
|
(0, shd, absIdx, stl, ltl, origIdx, findChr)
|
||||||
| (_, _) =>
|
| (_, _) =>
|
||||||
origIdx
|
origIdx
|
||||||
else
|
else
|
||||||
if String.sub (str, strPos) = findChr then
|
if String.sub (str, strPos) = findChr then
|
||||||
fResult absIdx
|
absIdx
|
||||||
else
|
else
|
||||||
helpNextChr
|
helpToNextChr
|
||||||
(strPos + 1, str, absIdx + 1, stl, ltl, origIdx, findChr, fResult)
|
(strPos + 1, str, absIdx + 1, stl, ltl, origIdx, findChr)
|
||||||
|
|
||||||
fun startNextChr (shd, strIdx, absIdx, stl, ltl, findChr, fResult) =
|
fun startToNextChr (shd, strIdx, absIdx, stl, ltl, findChr) =
|
||||||
(* we want to start iterating from next char after strIdx *)
|
(* we want to start iterating from next char after strIdx *)
|
||||||
if strIdx - 1 < String.size shd then
|
if strIdx - 1 < String.size shd then
|
||||||
helpNextChr
|
helpToNextChr
|
||||||
(strIdx + 1, shd, absIdx + 1, stl, ltl, absIdx, findChr, fResult)
|
(strIdx + 1, shd, absIdx + 1, stl, ltl, absIdx, findChr)
|
||||||
else
|
else
|
||||||
case (stl, ltl) of
|
case (stl, ltl) of
|
||||||
(stlhd :: stltl, ltlhd :: ltltl) =>
|
(stlhd :: stltl, ltlhd :: ltltl) =>
|
||||||
helpNextChr
|
helpToNextChr
|
||||||
(0, stlhd, absIdx + 1, stltl, ltltl, absIdx, findChr, fResult)
|
(0, stlhd, absIdx + 1, stltl, ltltl, absIdx, findChr)
|
||||||
| (_, _) =>
|
| (_, _) =>
|
||||||
(* tl is empty; just return absIdx *)
|
(* tl is empty; just return absIdx *)
|
||||||
absIdx
|
absIdx
|
||||||
|
|
||||||
fun nextChr (lineGap: LineGap.t, cursorIdx, chr, fResult) =
|
fun toNextChr (lineGap: LineGap.t, cursorIdx, chr) =
|
||||||
let
|
let
|
||||||
val {rightStrings, rightLines, idx = bufferIdx, ...} = lineGap
|
val {rightStrings, rightLines, idx = bufferIdx, ...} = lineGap
|
||||||
in
|
in
|
||||||
@@ -1304,8 +1304,8 @@ struct
|
|||||||
in
|
in
|
||||||
if strIdx < String.size shd then
|
if strIdx < String.size shd then
|
||||||
(* strIdx is in this string *)
|
(* strIdx is in this string *)
|
||||||
startNextChr
|
startToNextChr
|
||||||
(shd, strIdx, cursorIdx, stl, ltl, chr, fResult)
|
(shd, strIdx, cursorIdx, stl, ltl, chr)
|
||||||
else
|
else
|
||||||
(* strIdx is in tl *)
|
(* strIdx is in tl *)
|
||||||
(case (stl, ltl) of
|
(case (stl, ltl) of
|
||||||
@@ -1313,21 +1313,81 @@ struct
|
|||||||
let
|
let
|
||||||
val strIdx = strIdx - String.size shd
|
val strIdx = strIdx - String.size shd
|
||||||
in
|
in
|
||||||
startNextChr
|
startToNextChr
|
||||||
(shd, strIdx, cursorIdx, stl, ltl, chr, fResult)
|
(shd, strIdx, cursorIdx, stl, ltl, chr)
|
||||||
end
|
end
|
||||||
| (_, _) => cursorIdx)
|
| (_, _) => cursorIdx)
|
||||||
end
|
end
|
||||||
| (_, _) => cursorIdx
|
| (_, _) => cursorIdx
|
||||||
end
|
end
|
||||||
|
|
||||||
fun tillNextChrResult absIdx = absIdx - 1
|
fun helpTillNextChr (strPos, str, absIdx, stl, ltl, origIdx, findChr, lastNonLine) =
|
||||||
|
if strPos = String.size str then
|
||||||
fun tillNextChr (lineGap, cursorIdx, chr) =
|
case (stl, ltl) of
|
||||||
nextChr (lineGap, cursorIdx, chr, tillNextChrResult)
|
(shd :: stl, lhd :: ltl) =>
|
||||||
|
helpTillNextChr
|
||||||
fun toNextChrResult absIdx = absIdx
|
(0, shd, absIdx, stl, ltl, origIdx, findChr, lastNonLine)
|
||||||
|
| (_, _) =>
|
||||||
fun toNextChr (lineGap, cursorIdx, chr) =
|
origIdx
|
||||||
nextChr (lineGap, cursorIdx, chr, toNextChrResult)
|
else
|
||||||
|
let
|
||||||
|
val chr = String.sub (str, strPos)
|
||||||
|
in
|
||||||
|
if chr = findChr then
|
||||||
|
lastNonLine
|
||||||
|
else
|
||||||
|
let
|
||||||
|
val lastNonLine =
|
||||||
|
if chr = #"\n" orelse chr = #"\r" then
|
||||||
|
lastNonLine
|
||||||
|
else
|
||||||
|
absIdx
|
||||||
|
in
|
||||||
|
helpTillNextChr
|
||||||
|
(strPos + 1, str, absIdx + 1, stl, ltl, origIdx, findChr, lastNonLine)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
fun startTillNextChr (shd, strIdx, absIdx, stl, ltl, findChr) =
|
||||||
|
(* we want to start iterating from next char after strIdx *)
|
||||||
|
if strIdx - 1 < String.size shd then
|
||||||
|
helpTillNextChr
|
||||||
|
(strIdx + 1, shd, absIdx + 1, stl, ltl, absIdx, findChr, absIdx)
|
||||||
|
else
|
||||||
|
case (stl, ltl) of
|
||||||
|
(stlhd :: stltl, ltlhd :: ltltl) =>
|
||||||
|
helpTillNextChr
|
||||||
|
(0, stlhd, absIdx + 1, stltl, ltltl, absIdx, findChr, absIdx)
|
||||||
|
| (_, _) =>
|
||||||
|
(* tl is empty; just return absIdx *)
|
||||||
|
absIdx
|
||||||
|
|
||||||
|
fun tillNextChr (lineGap: LineGap.t, cursorIdx, chr) =
|
||||||
|
let
|
||||||
|
val {rightStrings, rightLines, idx = bufferIdx, ...} = 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 *)
|
||||||
|
startTillNextChr
|
||||||
|
(shd, strIdx, cursorIdx, stl, ltl, chr)
|
||||||
|
else
|
||||||
|
(* strIdx is in tl *)
|
||||||
|
(case (stl, ltl) of
|
||||||
|
(stlhd :: stltl, ltlhd :: ltltl) =>
|
||||||
|
let
|
||||||
|
val strIdx = strIdx - String.size shd
|
||||||
|
in
|
||||||
|
startTillNextChr
|
||||||
|
(shd, strIdx, cursorIdx, stl, ltl, chr)
|
||||||
|
end
|
||||||
|
| (_, _) => cursorIdx)
|
||||||
|
end
|
||||||
|
| (_, _) => cursorIdx
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
Reference in New Issue
Block a user