From f1a06f946dac7544c7b8f65f81dfe75d42662adf Mon Sep 17 00:00:00 2001 From: Humza Shahid Date: Sun, 14 Sep 2025 09:50:07 +0100 Subject: [PATCH] add searchScrollColumn to NORMAL_SEARCH_MODE variant, and update and recalculate it where needed --- fcore/app-type.sml | 8 ++- fcore/normal-mode/normal-mode.sml | 2 +- fcore/normal-mode/normal-search-finish.sml | 13 +++- fcore/normal-mode/normal-search-mode.sml | 83 ++++++++++++++++++---- fcore/text-scroll.sml | 3 + 5 files changed, 92 insertions(+), 17 deletions(-) diff --git a/fcore/app-type.sml b/fcore/app-type.sml index 7f9b251..186c314 100644 --- a/fcore/app-type.sml +++ b/fcore/app-type.sml @@ -2,8 +2,12 @@ structure AppType = struct datatype mode = NORMAL_MODE of string - | NORMAL_SEARCH_MODE of {searchString: string, tempSearchList: int vector, - searchCursorIdx: int} + | NORMAL_SEARCH_MODE of + { searchString: string + , tempSearchList: int vector + , searchCursorIdx: int + , searchScrollColumn: int + } type app_type = { mode: mode diff --git a/fcore/normal-mode/normal-mode.sml b/fcore/normal-mode/normal-mode.sml index c180f5b..b50fb1b 100644 --- a/fcore/normal-mode/normal-mode.sml +++ b/fcore/normal-mode/normal-mode.sml @@ -7,7 +7,7 @@ struct fun switchToNormalSearchMode (app: app_type) = NormalSearchFinish.onSearchChanged - (app, "", Vector.fromList [], 0, #buffer app) + (app, "", Vector.fromList [], 0, 0, #buffer app) fun getNumLength (pos, str) = if pos = String.size str then diff --git a/fcore/normal-mode/normal-search-finish.sml b/fcore/normal-mode/normal-search-finish.sml index 8bab34f..75f1390 100644 --- a/fcore/normal-mode/normal-search-finish.sml +++ b/fcore/normal-mode/normal-search-finish.sml @@ -4,7 +4,13 @@ struct open DrawMsg fun onSearchChanged - (app: app_type, searchString, tempSearchList, searchCursorIdx, buffer) = + ( app: app_type + , searchString + , tempSearchList + , searchCursorIdx + , searchScrollColumn + , buffer + ) = let val { buffer @@ -16,10 +22,15 @@ struct , ... } = app + val searchScrollColumn = + TextScroll.getScrollColumnFromString + (searchCursorIdx, windowWidth, searchScrollColumn) + val mode = NORMAL_SEARCH_MODE { searchString = searchString , tempSearchList = tempSearchList , searchCursorIdx = searchCursorIdx + , searchScrollColumn = searchScrollColumn } val floatWindowWidth = Real32.fromInt windowWidth diff --git a/fcore/normal-mode/normal-search-mode.sml b/fcore/normal-mode/normal-search-mode.sml index 4bf3f96..b9109f4 100644 --- a/fcore/normal-mode/normal-search-mode.sml +++ b/fcore/normal-mode/normal-search-mode.sml @@ -9,7 +9,8 @@ struct in SearchList.buildRange (buffer, unescapedString, cursorIdx + 1111) end - fun addChr (app: app_type, searchString, searchCursorIdx, chr) = + fun addChr + (app: app_type, searchString, searchCursorIdx, searchScrollColumn, chr) = let val {cursorIdx, buffer, ...} = app @@ -31,7 +32,13 @@ struct val tempSearchList = buildTempSearchList (searchString, buffer, cursorIdx) in NormalSearchFinish.onSearchChanged - (app, searchString, tempSearchList, searchCursorIdx, buffer) + ( app + , searchString + , tempSearchList + , searchCursorIdx + , searchScrollColumn + , buffer + ) end (* return to normal mode, keeping the same searchString and searchList @@ -87,7 +94,13 @@ struct (app, buffer, searchString, tempSearchList, startLine, mode, msgs) end - fun backspace (app: app_type, searchString, tempSearchList, searchCursorIdx) = + fun backspace + ( app: app_type + , searchString + , tempSearchList + , searchScrollColumn + , searchCursorIdx + ) = if searchCursorIdx = 0 then app else @@ -112,10 +125,17 @@ struct buildTempSearchList (searchString, buffer, cursorIdx) in NormalSearchFinish.onSearchChanged - (app, searchString, tempSearchList, searchCursorIdx, buffer) + ( app + , searchString + , tempSearchList + , searchCursorIdx + , searchScrollColumn + , buffer + ) end - fun moveLeft (app, searchString, tempSearchList, searchCursorIdx) = + fun moveLeft + (app, searchString, tempSearchList, searchCursorIdx, searchScrollColumn) = if searchCursorIdx = 0 then app else @@ -123,10 +143,17 @@ struct val searchCursorIdx = searchCursorIdx - 1 in NormalSearchFinish.onSearchChanged - (app, searchString, tempSearchList, searchCursorIdx, #buffer app) + ( app + , searchString + , tempSearchList + , searchCursorIdx + , searchScrollColumn + , #buffer app + ) end - fun moveRight (app, searchString, tempSearchList, searchCursorIdx) = + fun moveRight + (app, searchString, tempSearchList, searchCursorIdx, searchScrollColumn) = if searchCursorIdx = String.size searchString then app else @@ -134,20 +161,50 @@ struct val searchCursorIdx = searchCursorIdx + 1 in NormalSearchFinish.onSearchChanged - (app, searchString, tempSearchList, searchCursorIdx, #buffer app) + ( app + , searchString + , tempSearchList + , searchCursorIdx + , searchScrollColumn + , #buffer app + ) end - fun update (app, {searchString, tempSearchList, searchCursorIdx}, msg, time) = + fun update + ( app + , {searchString, tempSearchList, searchCursorIdx, searchScrollColumn} + , msg + , time + ) = case msg of - CHAR_EVENT chr => addChr (app, searchString, searchCursorIdx, chr) + CHAR_EVENT chr => + addChr (app, searchString, searchCursorIdx, searchScrollColumn, chr) | KEY_BACKSPACE => - backspace (app, searchString, tempSearchList, searchCursorIdx) + backspace + ( app + , searchString + , tempSearchList + , searchScrollColumn + , searchCursorIdx + ) | KEY_ESC => exitToNormalMode app | KEY_ENTER => saveSearch (app, searchString, tempSearchList, time) | ARROW_LEFT => - moveLeft (app, searchString, tempSearchList, searchCursorIdx) + moveLeft + ( app + , searchString + , tempSearchList + , searchCursorIdx + , searchScrollColumn + ) | ARROW_RIGHT => - moveRight (app, searchString, tempSearchList, searchCursorIdx) + moveRight + ( app + , searchString + , tempSearchList + , searchCursorIdx + , searchScrollColumn + ) | WITH_SEARCH_LIST (searchList, time) => NormalFinish.withSearchList (app, searchList, time) | RESIZE_EVENT (width, height) => diff --git a/fcore/text-scroll.sml b/fcore/text-scroll.sml index 351b2e8..7e7a324 100644 --- a/fcore/text-scroll.sml +++ b/fcore/text-scroll.sml @@ -34,6 +34,9 @@ struct (startOfLine, cursorIdx, windowWidth, prevScrollColumn) end + fun getScrollColumnFromString (cursorIdx, windowWidth, prevScrollColumn) = + calculateScrollColumn (0, cursorIdx, windowWidth, prevScrollColumn) + fun getStartLine (prevLineNumber, cursorLine, windowHeight) = if cursorLine <= (prevLineNumber + 3) then (* cursorLine is prior to or same as prevLineNumber,