diff --git a/fcore/app-update.sml b/fcore/app-update.sml index a359f7b..4460afb 100644 --- a/fcore/app-update.sml +++ b/fcore/app-update.sml @@ -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) diff --git a/fcore/cursor.sml b/fcore/cursor.sml index e6de8e0..881d7ec 100644 --- a/fcore/cursor.sml +++ b/fcore/cursor.sml @@ -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 diff --git a/shf b/shf index d569cdd..d22d1c9 100755 Binary files a/shf and b/shf differ diff --git a/temp.txt b/temp.txt index 877df0c..d6ea8a2 100644 --- a/temp.txt +++ b/temp.txt @@ -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