amend cursor.sml's 'helpTillNextChr' function to work with new line break scheme, and use it to implement 'delete till' functionality starting with 'dt' (for example, 'dta' deletes till 'a', 'dts'detetes till 's', etc.)
This commit is contained in:
@@ -432,7 +432,7 @@ struct
|
||||
else
|
||||
let
|
||||
val buffer = LineGap.goToIdx (cursorIdx, buffer)
|
||||
val otherIdx = fMove (buffer, cursorIdx, chr)
|
||||
val otherIdx = fMove (buffer, cursorIdx, chr) + 1
|
||||
|
||||
val low = Int.min (cursorIdx, otherIdx)
|
||||
val high = Int.max (cursorIdx, otherIdx)
|
||||
@@ -574,7 +574,13 @@ struct
|
||||
case String.sub (str, strPos + 1) of
|
||||
#"t" =>
|
||||
(* todo: delete till chr, forwards *)
|
||||
clearMode app
|
||||
(case newCmd of
|
||||
CHAR_EVENT chr =>
|
||||
deleteToChr (app, 1, Cursor.tillNextChr, chr)
|
||||
| KEY_ESC =>
|
||||
clearMode app
|
||||
| RESIZE_EVENT (width, height) =>
|
||||
resizeText (app, width, height))
|
||||
| #"T" =>
|
||||
(* todo: delete till chr, backwards *)
|
||||
clearMode app
|
||||
@@ -662,9 +668,6 @@ struct
|
||||
CHAR_EVENT chr => handleChr (app, count, chr, str)
|
||||
| KEY_ESC => clearMode app
|
||||
| RESIZE_EVENT (width, height) => resizeText (app, width, height)
|
||||
else if numLength + 1 < String.size str then
|
||||
(* continue parsing. *)
|
||||
parseAfterCount (numLength + 1, str, count, app, newCmd)
|
||||
else
|
||||
(* continue parsing. *)
|
||||
parseAfterCount (numLength, str, count, app, newCmd)
|
||||
|
||||
@@ -1264,48 +1264,62 @@ struct
|
||||
(* tl is empty; just return absIdx *)
|
||||
absIdx
|
||||
|
||||
fun helpTillNextChr (strPos, str, absIdx, stl, ltl, origIdx, findChr, lastNonLine) =
|
||||
if strPos = String.size str then
|
||||
case (stl, ltl) of
|
||||
(shd :: stl, lhd :: ltl) =>
|
||||
helpTillNextChr
|
||||
(0, shd, absIdx, stl, ltl, origIdx, findChr, lastNonLine)
|
||||
| (_, _) =>
|
||||
origIdx
|
||||
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 helpTillNextChr
|
||||
( strPos, str, absIdx, stl, ltl
|
||||
, origIdx, findChr, lastNonLine, lastLine
|
||||
) =
|
||||
if strPos = String.size str then
|
||||
case (stl, ltl) of
|
||||
(shd :: stl, lhd :: ltl) =>
|
||||
helpTillNextChr
|
||||
(0, shd, absIdx, stl, ltl, origIdx, findChr, lastNonLine, lastLine)
|
||||
| (_, _) =>
|
||||
origIdx
|
||||
else
|
||||
let
|
||||
val chr = String.sub (str, strPos)
|
||||
in
|
||||
if chr = findChr then
|
||||
if lastLine = lastNonLine + 1 then
|
||||
(* graphical-chr -> \n
|
||||
* so return graphical-chr *)
|
||||
lastNonLine
|
||||
else
|
||||
Int.max (lastLine, lastNonLine)
|
||||
else
|
||||
let
|
||||
val lastLine =
|
||||
if chr = #"\n" then
|
||||
absIdx
|
||||
else
|
||||
lastLine
|
||||
val lastNonLine =
|
||||
if chr = #"\n" then
|
||||
lastNonLine
|
||||
else
|
||||
absIdx
|
||||
in
|
||||
helpTillNextChr
|
||||
( strPos + 1, str, absIdx + 1, stl, ltl
|
||||
, origIdx, findChr, lastNonLine, lastLine
|
||||
)
|
||||
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
|
||||
if strIdx + 1 < String.size shd then
|
||||
helpTillNextChr
|
||||
(strIdx + 1, shd, absIdx + 1, stl, ltl, absIdx, findChr, absIdx)
|
||||
(strIdx + 1, shd, absIdx + 1, stl, ltl, absIdx, findChr, absIdx, absIdx)
|
||||
else
|
||||
case (stl, ltl) of
|
||||
(stlhd :: stltl, ltlhd :: ltltl) =>
|
||||
helpTillNextChr
|
||||
(0, stlhd, absIdx + 1, stltl, ltltl, absIdx, findChr, absIdx)
|
||||
(0, stlhd, absIdx + 1, stltl, ltltl, absIdx, findChr, absIdx, absIdx)
|
||||
| (_, _) =>
|
||||
(* tl is empty; just return absIdx *)
|
||||
absIdx
|
||||
|
||||
|
||||
fun nextChr (lineGap: LineGap.t, cursorIdx, chr, fStart) =
|
||||
let
|
||||
val {rightStrings, rightLines, idx = bufferIdx, ...} = lineGap
|
||||
@@ -1328,7 +1342,7 @@ struct
|
||||
val strIdx = strIdx - String.size shd
|
||||
in
|
||||
fStart
|
||||
(shd, strIdx, cursorIdx, stltl, ltltl, chr)
|
||||
(stlhd, strIdx, cursorIdx, stltl, ltltl, chr)
|
||||
end
|
||||
| (_, _) => cursorIdx)
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user