diff --git a/fcore/cursor.sml b/fcore/cursor.sml index 9e0dc1f..fae1c1e 100644 --- a/fcore/cursor.sml +++ b/fcore/cursor.sml @@ -307,6 +307,55 @@ struct fun toNextChr (lineGap, cursorIdx, chr) = nextChr (lineGap, cursorIdx, chr, startToNextChr) + structure ToNextChr = + MakeIfCharFolderNext + (struct + type env = {findChr: char, count: int} + + fun helpToNextChr + (strPos, str, absIdx, stl, lastFoundIdx, findChr, count) = + if strPos = String.size str then + case stl of + str :: stl => + helpToNextChr + (0, str, absIdx, stl, lastFoundIdx, findChr, count) + | [] => lastFoundIdx + else + let + val chr = String.sub (str, strPos) + in + if chr = findChr then + if count - 1 = 0 then + absIdx + else + helpToNextChr + ( strPos + 1 + , str + , absIdx + 1 + , stl + , absIdx + , findChr + , count - 1 + ) + else + helpToNextChr + ( strPos + 1 + , str + , absIdx + 1 + , stl + , lastFoundIdx + , findChr + , count + ) + end + + fun fStart (strPos, str, _, absIdx, stl, _, {findChr, count}) = + (* we want to start iterating from char after cursor *) + helpToNextChr (strPos + 1, str, absIdx + 1, stl, ~1, findChr, count) + end) + + val toNextChrNew = ToNextChr.foldNext + structure ToPrevChr = MakeIfCharFolderPrev (struct diff --git a/fcore/normal-mode/normal-mode.sml b/fcore/normal-mode/normal-mode.sml index 353f6b3..8581198 100644 --- a/fcore/normal-mode/normal-mode.sml +++ b/fcore/normal-mode/normal-mode.sml @@ -571,9 +571,7 @@ struct parseMoveToChr (1, app, Cursor.tillPrevChr, chrCmd) | #"y" => ParseYank.parseYank (strPos, str, count, app, chrCmd, time) | #"d" => ParseDelete.parseDelete (strPos, str, count, app, chrCmd, time) - | #"f" => - (* to chr, forward *) - parseMoveToChr (count, app, Cursor.toNextChr, chrCmd) + | #"f" => (* to chr, forward *) NormalMove.toNextChr (app, count, chrCmd) | #"F" => (* to chr, backward *) parseMoveToChr (count, app, Cursor.toPrevChr, chrCmd) diff --git a/fcore/normal-mode/normal-move.sml b/fcore/normal-mode/normal-move.sml index 1b9da80..f14f081 100644 --- a/fcore/normal-mode/normal-move.sml +++ b/fcore/normal-mode/normal-move.sml @@ -516,4 +516,18 @@ struct NormalFinish.buildTextAndClear (app, buffer, newCursorIdx, searchList, [], bufferModifyTime) end + + fun toNextChr (app: app_type, count, chr) = + let + val {cursorIdx, buffer, searchList, bufferModifyTime, ...} = app + val buffer = LineGap.goToIdx (cursorIdx, buffer) + val newCursorIdx = + Cursor.toNextChrNew (buffer, cursorIdx, {findChr = chr, count = count}) + in + if newCursorIdx = ~1 then + NormalFinish.clearMode app + else + NormalFinish.buildTextAndClear + (app, buffer, newCursorIdx, searchList, [], bufferModifyTime) + end end