add equivalent of vi's 'F'
This commit is contained in:
@@ -264,7 +264,7 @@ struct
|
|||||||
handleNextChr (count, app, Cursor.toNextChr, newCmd)
|
handleNextChr (count, app, Cursor.toNextChr, newCmd)
|
||||||
| #"F" =>
|
| #"F" =>
|
||||||
(* to chr, backward *)
|
(* to chr, backward *)
|
||||||
clearMode app
|
handleNextChr (count, app, Cursor.toPrevChr, newCmd)
|
||||||
| #"g" =>
|
| #"g" =>
|
||||||
(* go *)
|
(* go *)
|
||||||
clearMode app
|
clearMode app
|
||||||
|
|||||||
@@ -977,7 +977,7 @@ struct
|
|||||||
(case (stl, ltl) of
|
(case (stl, ltl) of
|
||||||
(stlhd :: stltl, ltlhd :: ltltl) =>
|
(stlhd :: stltl, ltlhd :: ltltl) =>
|
||||||
let val strIdx = strIdx - String.size shd
|
let val strIdx = strIdx - String.size shd
|
||||||
in fNext (strIdx, shd, cursorIdx, stl, ltl)
|
in fNext (strIdx, shd, cursorIdx, stltl, ltltl)
|
||||||
end
|
end
|
||||||
| (_, _) => cursorIdx)
|
| (_, _) => cursorIdx)
|
||||||
end
|
end
|
||||||
@@ -1197,8 +1197,7 @@ struct
|
|||||||
fun endOfWORD (lineGap, cursorIdx) =
|
fun endOfWORD (lineGap, cursorIdx) =
|
||||||
toEndOfWord (lineGap, cursorIdx, helpEndOfWORD)
|
toEndOfWord (lineGap, cursorIdx, helpEndOfWORD)
|
||||||
|
|
||||||
fun helpFirstNonSpaceChr
|
fun helpFirstNonSpaceChr (strPos, str, absIdx, stl, ltl) =
|
||||||
(strPos, str, absIdx, stl, ltl) =
|
|
||||||
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) =>
|
||||||
@@ -1217,8 +1216,7 @@ struct
|
|||||||
absIdx
|
absIdx
|
||||||
end
|
end
|
||||||
|
|
||||||
fun startFirstNonSpaceChr
|
fun startFirstNonSpaceChr (shd, strIdx, absIdx, stl, ltl) =
|
||||||
(shd, strIdx, absIdx, stl, ltl) =
|
|
||||||
if strIdx < String.size shd then
|
if strIdx < String.size shd then
|
||||||
helpFirstNonSpaceChr
|
helpFirstNonSpaceChr
|
||||||
(strIdx, shd, absIdx, stl, ltl)
|
(strIdx, shd, absIdx, stl, ltl)
|
||||||
@@ -1314,7 +1312,7 @@ struct
|
|||||||
val strIdx = strIdx - String.size shd
|
val strIdx = strIdx - String.size shd
|
||||||
in
|
in
|
||||||
startToNextChr
|
startToNextChr
|
||||||
(shd, strIdx, cursorIdx, stl, ltl, chr)
|
(shd, strIdx, cursorIdx, stltl, ltltl, chr)
|
||||||
end
|
end
|
||||||
| (_, _) => cursorIdx)
|
| (_, _) => cursorIdx)
|
||||||
end
|
end
|
||||||
@@ -1384,7 +1382,67 @@ struct
|
|||||||
val strIdx = strIdx - String.size shd
|
val strIdx = strIdx - String.size shd
|
||||||
in
|
in
|
||||||
startTillNextChr
|
startTillNextChr
|
||||||
(shd, strIdx, cursorIdx, stl, ltl, chr)
|
(shd, strIdx, cursorIdx, stltl, ltltl, chr)
|
||||||
|
end
|
||||||
|
| (_, _) => cursorIdx)
|
||||||
|
end
|
||||||
|
| (_, _) => cursorIdx
|
||||||
|
end
|
||||||
|
|
||||||
|
fun helpToPrevChr (strPos, str, absIdx, stl, ltl, origIdx, findChr) =
|
||||||
|
if strPos = 0 then
|
||||||
|
case (stl, ltl) of
|
||||||
|
(shd :: stl, lhd :: ltl) =>
|
||||||
|
helpToPrevChr
|
||||||
|
(String.size shd - 1, shd, absIdx, stl, ltl, origIdx, findChr)
|
||||||
|
| (_, _) =>
|
||||||
|
origIdx
|
||||||
|
else
|
||||||
|
if String.sub (str, strPos) = findChr then
|
||||||
|
absIdx
|
||||||
|
else
|
||||||
|
helpToPrevChr
|
||||||
|
(strPos - 1, str, absIdx - 1, stl, ltl, origIdx, findChr)
|
||||||
|
|
||||||
|
fun startToPrevChr (shd, strIdx, absIdx, stl, ltl, findChr) =
|
||||||
|
(* we want to start iterating from Prev char after strIdx *)
|
||||||
|
if strIdx > 0 then
|
||||||
|
helpToPrevChr
|
||||||
|
(strIdx - 1, shd, absIdx - 1, stl, ltl, absIdx, findChr)
|
||||||
|
else
|
||||||
|
case (stl, ltl) of
|
||||||
|
(stlhd :: stltl, ltlhd :: ltltl) =>
|
||||||
|
helpToPrevChr
|
||||||
|
(String.size stlhd - 1, stlhd, absIdx - 1, stltl, ltltl, absIdx, findChr)
|
||||||
|
| (_, _) =>
|
||||||
|
(* tl is empty; return 0 for lineGap start *)
|
||||||
|
0
|
||||||
|
|
||||||
|
fun toPrevChr (lineGap: LineGap.t, cursorIdx, chr) =
|
||||||
|
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 *)
|
||||||
|
startToPrevChr
|
||||||
|
(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
|
||||||
|
startToPrevChr
|
||||||
|
(shd, strIdx, cursorIdx, leftStrings, leftLines, chr)
|
||||||
end
|
end
|
||||||
| (_, _) => cursorIdx)
|
| (_, _) => cursorIdx)
|
||||||
end
|
end
|
||||||
|
|||||||
Reference in New Issue
Block a user