From 3e69c41d8f5c9be5f7264de953e1b3c4a3612c1c Mon Sep 17 00:00:00 2001 From: Humza Shahid Date: Mon, 1 Sep 2025 11:33:01 +0100 Subject: [PATCH] implement functionality for left and right arrow keys to move cursor left/right when entering searchString in NORMAL_SEARCH_MODE --- fcore/normal-mode/normal-mode.sml | 5 +++++ fcore/normal-mode/normal-search-mode.sml | 28 ++++++++++++++++++++++++ 2 files changed, 33 insertions(+) diff --git a/fcore/normal-mode/normal-mode.sml b/fcore/normal-mode/normal-mode.sml index 052bd5b..18a4f08 100644 --- a/fcore/normal-mode/normal-mode.sml +++ b/fcore/normal-mode/normal-mode.sml @@ -267,4 +267,9 @@ struct NormalFinish.withSearchList (app, searchList) | KEY_ENTER => app | KEY_BACKSPACE => app + (* todo *) + | ARROW_RIGHT => app + | ARROW_LEFT => app + | ARROW_UP => app + | ARROW_DOWN => app end diff --git a/fcore/normal-mode/normal-search-mode.sml b/fcore/normal-mode/normal-search-mode.sml index ea8930f..8bcce56 100644 --- a/fcore/normal-mode/normal-search-mode.sml +++ b/fcore/normal-mode/normal-search-mode.sml @@ -102,6 +102,28 @@ struct (app, searchString, tempSearchList, searchCursorIdx, buffer) end + fun moveLeft (app, searchString, tempSearchList, searchCursorIdx) = + if searchCursorIdx = 0 then + app + else + let + val searchCursorIdx = searchCursorIdx - 1 + in + NormalSearchFinish.onSearchChanged + (app, searchString, tempSearchList, searchCursorIdx, #buffer app) + end + + fun moveRight (app, searchString, tempSearchList, searchCursorIdx) = + if searchCursorIdx = String.size searchString then + app + else + let + val searchCursorIdx = searchCursorIdx + 1 + in + NormalSearchFinish.onSearchChanged + (app, searchString, tempSearchList, searchCursorIdx, #buffer app) + end + fun update (app, {searchString, tempSearchList, searchCursorIdx}, msg, time) = case msg of CHAR_EVENT chr => addChr (app, searchString, searchCursorIdx, chr) @@ -111,4 +133,10 @@ struct | KEY_ENTER => saveSearch (app, searchString, tempSearchList) | RESIZE_EVENT (width, height) => app | WITH_SEARCH_LIST searchList => app + | ARROW_LEFT => + moveLeft (app, searchString, tempSearchList, searchCursorIdx) + | ARROW_RIGHT => + moveRight (app, searchString, tempSearchList, searchCursorIdx) + | ARROW_UP => app + | ARROW_DOWN => app end