From c94aa720159fee74464017d7f58b4c7c2556c254 Mon Sep 17 00:00:00 2001 From: Humza Shahid Date: Wed, 17 Sep 2025 02:20:36 +0100 Subject: [PATCH] create 'MakeIfCharFolderNext' functor, which mirrors the 'MakeIfCharFolderPrev' functor that we already have --- fcore/cursor-dfa/make-dfa-loop.sml | 38 ++++++++++++++++++++++++++++++ 1 file changed, 38 insertions(+) diff --git a/fcore/cursor-dfa/make-dfa-loop.sml b/fcore/cursor-dfa/make-dfa-loop.sml index 628878c..50712a5 100644 --- a/fcore/cursor-dfa/make-dfa-loop.sml +++ b/fcore/cursor-dfa/make-dfa-loop.sml @@ -245,3 +245,41 @@ struct | (_, _) => (* nowhere to go, so return cursorIdx *) cursorIdx end end + +functor MakeIfCharFolderNext(Fn: MAKE_IF_CHAR_FOLDER) = +struct + fun foldNext (lineGap: LineGap.t, cursorIdx, env: Fn.env) = + let + val {rightStrings, idx = bufferIdx, rightLines, ...} = lineGap + in + case (rightStrings, rightLines) of + (strHd :: strTl, lnHd :: lnTl) => + let + (* convert absolute cursorIdx to idx relative to hd string *) + val strIdx = cursorIdx - bufferIdx + in + if strIdx < String.size strHd then + (* strIdx is in this string *) + Fn.fStart (strIdx, strHd, lnHd, cursorIdx, strTl, lnTl, env) + else + (* strIdx must be in the strTl *) + (case (strTl, lnTl) of + (nestStrHd :: nestStrTl, nestLnHd :: nestLnTl) => + let + val strIdx = strIdx - String.size strHd + in + Fn.fStart + ( strIdx + , nestStrHd + , nestLnHd + , cursorIdx + , nestStrTl + , nestLnTl + , env + ) + end + | (_, _) => cursorIdx) + end + | (_, _) => (* nowhere to go, so return cursorIdx *) cursorIdx + end +end