From 96521f358f8fb5b8aa39e2b125eee0707d9518e6 Mon Sep 17 00:00:00 2001 From: Humza Shahid Date: Tue, 16 Sep 2025 21:35:48 +0100 Subject: [PATCH] when looping through a DFA in a functor, make sure we return the absolute index to the calling function and not a modified version of the absolute index which has already been clipped --- fcore/cursor-dfa/make-dfa-loop.sml | 2 +- fcore/move.sml | 5 +++++ 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/fcore/cursor-dfa/make-dfa-loop.sml b/fcore/cursor-dfa/make-dfa-loop.sml index f102d56..628878c 100644 --- a/fcore/cursor-dfa/make-dfa-loop.sml +++ b/fcore/cursor-dfa/make-dfa-loop.sml @@ -147,7 +147,7 @@ struct if idx = String.size str then case tl of str :: tl => foldNext (0, absIdx, str, tl, currentState, counter) - | [] => Int.max (absIdx - 2, 0) + | [] => absIdx else let val chr = String.sub (str, idx) diff --git a/fcore/move.sml b/fcore/move.sml index 359a902..c70d9a8 100644 --- a/fcore/move.sml +++ b/fcore/move.sml @@ -66,6 +66,11 @@ struct val {buffer, cursorIdx, searchList, bufferModifyTime, ...} = app val buffer = LineGap.goToIdx (cursorIdx, buffer) val cursorIdx = Fn.fMove (buffer, cursorIdx, count) + + val textLength = #textLength buffer + val cursorIdx = + if cursorIdx >= textLength - 2 then Int.max (textLength - 2, 0) + else cursorIdx in NormalFinish.buildTextAndClear (app, buffer, cursorIdx, searchList, [], bufferModifyTime)