From 5d6dbb0403b55e76d20e0a7e8c9825bde72a3e1a Mon Sep 17 00:00:00 2001 From: Humza Shahid Date: Thu, 7 Aug 2025 13:22:10 +0100 Subject: [PATCH] add functions to move to prev/next match --- fcore/app-update.sml | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/fcore/app-update.sml b/fcore/app-update.sml index 76834e2..c4568e7 100644 --- a/fcore/app-update.sml +++ b/fcore/app-update.sml @@ -366,6 +366,24 @@ struct | RESIZE_EVENT (width, height) => resizeText (app, width, height) | WITH_SEARCH_LIST searchList => withSearchList (app, searchList) + fun moveToNextMatch (app: app_type, count) = + let + val {cursorIdx, searchList, buffer, ...} = app + val newCursorIdx = SearchList.nextMatch (cursorIdx, searchList, count) + in + if newCursorIdx = ~1 then clearMode app + else buildTextAndClearAfterChr (app, buffer, newCursorIdx, searchList, []) + end + + fun moveToPrevMatch (app: app_type, count) = + let + val {cursorIdx, searchList, buffer, ...} = app + val newCursorIdx = SearchList.prevMatch (cursorIdx, searchList, count) + in + if newCursorIdx = ~1 then clearMode app + else buildTextAndClearAfterChr (app, buffer, newCursorIdx, searchList, []) + end + (* text-delete functions *) (** equivalent of vi's 'x' command **) fun helpRemoveChr (app: app_type, buffer, cursorIdx, count) = @@ -707,6 +725,8 @@ struct | #"B" => MoveToPrevWORD.move (app, count) | #"e" => MoveToEndOfWord.move (app, count) | #"E" => MoveToEndOfWORD.move (app, count) + | #"n" => moveToNextMatch (app, count) + | #"N" => moveToPrevMatch (app, count) | #"z" => centreToCursor app (* can only move to start or end of line once * so hardcode count as 1 *)