add functions to move to prev/next match

This commit is contained in:
2025-08-07 13:22:10 +01:00
parent 268fd47d7e
commit 5d6dbb0403

View File

@@ -366,6 +366,24 @@ struct
| RESIZE_EVENT (width, height) => resizeText (app, width, height) | RESIZE_EVENT (width, height) => resizeText (app, width, height)
| WITH_SEARCH_LIST searchList => withSearchList (app, searchList) | 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 *) (* text-delete functions *)
(** equivalent of vi's 'x' command **) (** equivalent of vi's 'x' command **)
fun helpRemoveChr (app: app_type, buffer, cursorIdx, count) = fun helpRemoveChr (app: app_type, buffer, cursorIdx, count) =
@@ -707,6 +725,8 @@ struct
| #"B" => MoveToPrevWORD.move (app, count) | #"B" => MoveToPrevWORD.move (app, count)
| #"e" => MoveToEndOfWord.move (app, count) | #"e" => MoveToEndOfWord.move (app, count)
| #"E" => MoveToEndOfWORD.move (app, count) | #"E" => MoveToEndOfWORD.move (app, count)
| #"n" => moveToNextMatch (app, count)
| #"N" => moveToPrevMatch (app, count)
| #"z" => centreToCursor app | #"z" => centreToCursor app
(* can only move to start or end of line once (* can only move to start or end of line once
* so hardcode count as 1 *) * so hardcode count as 1 *)