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:
2024-11-09 05:35:32 +00:00
parent e4f46295d4
commit d4d0236dab
4 changed files with 54 additions and 37 deletions

View File

@@ -432,7 +432,7 @@ struct
else else
let let
val buffer = LineGap.goToIdx (cursorIdx, buffer) 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 low = Int.min (cursorIdx, otherIdx)
val high = Int.max (cursorIdx, otherIdx) val high = Int.max (cursorIdx, otherIdx)
@@ -574,7 +574,13 @@ struct
case String.sub (str, strPos + 1) of case String.sub (str, strPos + 1) of
#"t" => #"t" =>
(* todo: delete till chr, forwards *) (* 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" => | #"T" =>
(* todo: delete till chr, backwards *) (* todo: delete till chr, backwards *)
clearMode app clearMode app
@@ -662,9 +668,6 @@ struct
CHAR_EVENT chr => handleChr (app, count, chr, str) CHAR_EVENT chr => handleChr (app, count, chr, str)
| KEY_ESC => clearMode app | KEY_ESC => clearMode app
| RESIZE_EVENT (width, height) => resizeText (app, width, height) | 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 else
(* continue parsing. *) (* continue parsing. *)
parseAfterCount (numLength, str, count, app, newCmd) parseAfterCount (numLength, str, count, app, newCmd)

View File

@@ -1264,48 +1264,62 @@ struct
(* tl is empty; just return absIdx *) (* tl is empty; just return absIdx *)
absIdx absIdx
fun helpTillNextChr (strPos, str, absIdx, stl, ltl, origIdx, findChr, lastNonLine) = fun helpTillNextChr
if strPos = String.size str then ( strPos, str, absIdx, stl, ltl
case (stl, ltl) of , origIdx, findChr, lastNonLine, lastLine
(shd :: stl, lhd :: ltl) => ) =
helpTillNextChr if strPos = String.size str then
(0, shd, absIdx, stl, ltl, origIdx, findChr, lastNonLine) case (stl, ltl) of
| (_, _) => (shd :: stl, lhd :: ltl) =>
origIdx helpTillNextChr
else (0, shd, absIdx, stl, ltl, origIdx, findChr, lastNonLine, lastLine)
let | (_, _) =>
val chr = String.sub (str, strPos) origIdx
in else
if chr = findChr then let
lastNonLine val chr = String.sub (str, strPos)
else in
let if chr = findChr then
val lastNonLine = if lastLine = lastNonLine + 1 then
if chr = #"\n" orelse chr = #"\r" then (* graphical-chr -> \n
lastNonLine * so return graphical-chr *)
else lastNonLine
absIdx else
in Int.max (lastLine, lastNonLine)
helpTillNextChr else
(strPos + 1, str, absIdx + 1, stl, ltl, origIdx, findChr, lastNonLine) let
end val lastLine =
end 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) = fun startTillNextChr (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
helpTillNextChr helpTillNextChr
(strIdx + 1, shd, absIdx + 1, stl, ltl, absIdx, findChr, absIdx) (strIdx + 1, shd, absIdx + 1, stl, ltl, absIdx, findChr, absIdx, absIdx)
else else
case (stl, ltl) of case (stl, ltl) of
(stlhd :: stltl, ltlhd :: ltltl) => (stlhd :: stltl, ltlhd :: ltltl) =>
helpTillNextChr 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 *) (* tl is empty; just return absIdx *)
absIdx absIdx
fun nextChr (lineGap: LineGap.t, cursorIdx, chr, fStart) = fun nextChr (lineGap: LineGap.t, cursorIdx, chr, fStart) =
let let
val {rightStrings, rightLines, idx = bufferIdx, ...} = lineGap val {rightStrings, rightLines, idx = bufferIdx, ...} = lineGap
@@ -1328,7 +1342,7 @@ struct
val strIdx = strIdx - String.size shd val strIdx = strIdx - String.size shd
in in
fStart fStart
(shd, strIdx, cursorIdx, stltl, ltltl, chr) (stlhd, strIdx, cursorIdx, stltl, ltltl, chr)
end end
| (_, _) => cursorIdx) | (_, _) => cursorIdx)
end end

BIN
shf

Binary file not shown.

View File

@@ -1,5 +1,5 @@
signature TEXT_BUILDER = signature TEXT_BUILDER =
sig aaron baron carrot durian aaron baron carrot durian
(* Prerequisite: LineGap is moved to requested line first. *) (* Prerequisite: LineGap is moved to requested line first. *)
val build: int * int * LineGap.t * int * int val build: int * int * LineGap.t * int * int
-> MailboxType.t list -> MailboxType.t list