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
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 *)
(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)

View File

@@ -1264,12 +1264,15 @@ struct
(* tl is empty; just return absIdx *)
absIdx
fun helpTillNextChr (strPos, str, absIdx, stl, ltl, origIdx, findChr, lastNonLine) =
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)
(0, shd, absIdx, stl, ltl, origIdx, findChr, lastNonLine, lastLine)
| (_, _) =>
origIdx
else
@@ -1277,35 +1280,46 @@ struct
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" orelse chr = #"\r" then
if chr = #"\n" then
lastNonLine
else
absIdx
in
helpTillNextChr
(strPos + 1, str, absIdx + 1, stl, ltl, origIdx, findChr, lastNonLine)
( 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

BIN
shf

Binary file not shown.

View File

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