From 1296ce367bc53cb26c5be48840a2a6f54f4ea261 Mon Sep 17 00:00:00 2001 From: Humza Shahid Date: Mon, 1 Sep 2025 12:52:26 +0100 Subject: [PATCH] handle resize event and concurrent (permanent and full) search result in NORMAL_SEARCH_MODE --- fcore/normal-mode/normal-search-finish.sml | 72 ++++++++++++++++++- fcore/normal-mode/normal-search-mode-with.sml | 57 +++++++++++++++ fcore/normal-mode/normal-search-mode.sml | 14 +++- 3 files changed, 139 insertions(+), 4 deletions(-) diff --git a/fcore/normal-mode/normal-search-finish.sml b/fcore/normal-mode/normal-search-finish.sml index f801c76..bfe7832 100644 --- a/fcore/normal-mode/normal-search-finish.sml +++ b/fcore/normal-mode/normal-search-finish.sml @@ -1,12 +1,11 @@ structure NormalSearchFinish = struct open AppType + open DrawMsg fun onSearchChanged (app: app_type, searchString, tempSearchList, searchCursorIdx, buffer) = let - open DrawMsg - val {buffer, cursorIdx, startLine, windowWidth, windowHeight, ...} = app val mode = NORMAL_SEARCH_MODE { searchString = searchString @@ -74,4 +73,73 @@ struct (app, buffer, startLine, mode, msgs) end + fun resize + ( app: app_type + , newWindowWidth + , newWindowHeight + , searchCursorIdx + , tempSearchList + ) = + let + val {buffer, cursorIdx, startLine, searchString, ...} = app + + val floatWindowWidth = Real32.fromInt newWindowWidth + val floatWindowHeight = Real32.fromInt newWindowHeight + + val searchStringPosY = newWindowHeight - TextConstants.ySpace - 5 + + val initialTextAcc = TextBuilder.buildLineToList + ( searchString + , 5 + , searchStringPosY + , newWindowWidth + , floatWindowWidth + , floatWindowHeight + ) + + val cursor = + let + val xpos = TextConstants.xSpace * (searchCursorIdx + 1) + 5 + val x = Real32.fromInt xpos + val y = Real32.fromInt searchStringPosY + val r: Real32.real = 0.67 + val g: Real32.real = 0.51 + val b: Real32.real = 0.83 + in + PipeCursor.lerp + ( x + , y + , TextConstants.scale + , floatWindowWidth + , floatWindowHeight + , r + , g + , b + ) + end + + val buffer = LineGap.goToLine (startLine, buffer) + val startLine = TextWindow.getStartLine + (buffer, startLine, cursorIdx, newWindowWidth, newWindowHeight) + + val remainingWindowHeight = newWindowHeight - (TextConstants.ySpace * 2) + + val msgs = TextBuilder.buildWithExisting + ( startLine + , cursorIdx + , buffer + , newWindowWidth + , remainingWindowHeight + , floatWindowWidth + , floatWindowHeight + , tempSearchList + , searchString + , [] + , cursor :: initialTextAcc + , [] + ) + in + NormalSearchModeWith.bufferAndSize + (app, buffer, newWindowWidth, newWindowHeight, msgs) + end end diff --git a/fcore/normal-mode/normal-search-mode-with.sml b/fcore/normal-mode/normal-search-mode-with.sml index e13f939..ef8e1c4 100644 --- a/fcore/normal-mode/normal-search-mode-with.sml +++ b/fcore/normal-mode/normal-search-mode-with.sml @@ -66,4 +66,61 @@ struct , cursorIdx = cursorIdx } end + + fun searchList (app: app_type, newSearchList) = + let + val + { mode + , buffer + , searchString + , searchList = _ + , startLine + , msgs + , bufferModifyTime + , windowWidth + , windowHeight + , cursorIdx + } = app + in + { mode = mode + , searchList = newSearchList + , buffer = buffer + , startLine = startLine + , msgs = msgs + , searchString = searchString + , bufferModifyTime = bufferModifyTime + , windowWidth = windowWidth + , windowHeight = windowHeight + , cursorIdx = cursorIdx + } + end + + fun bufferAndSize + (app: app_type, newBuffer, newWindowWidth, newWindowHeight, newMsgs) = + let + val + { mode + , windowWidth = _ + , windowHeight = _ + , msgs = _ + , buffer = _ + , searchString + , searchList + , startLine + , bufferModifyTime + , cursorIdx + } = app + in + { mode = mode + , buffer = newBuffer + , windowWidth = newWindowWidth + , windowHeight = newWindowHeight + , msgs = newMsgs + , searchList = searchList + , startLine = startLine + , searchString = searchString + , bufferModifyTime = bufferModifyTime + , cursorIdx = cursorIdx + } + end end diff --git a/fcore/normal-mode/normal-search-mode.sml b/fcore/normal-mode/normal-search-mode.sml index 8bcce56..4bea579 100644 --- a/fcore/normal-mode/normal-search-mode.sml +++ b/fcore/normal-mode/normal-search-mode.sml @@ -131,12 +131,22 @@ struct backspace (app, searchString, tempSearchList, searchCursorIdx) | KEY_ESC => exitToNormalMode app | 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) + | WITH_SEARCH_LIST searchList => + NormalSearchModeWith.searchList (app, searchList) + | RESIZE_EVENT (width, height) => + NormalSearchFinish.resize + (app, width, height, searchCursorIdx, tempSearchList) + + (* In Vim's search mode, the up and down arrows can be used + * to scroll through the search history. + * I don't find this feature too useful as it is often easier to type + * the whole search string again, so I'm leaving it unimplemented + * until/unless I find that I wish this functionality was there + * while using the program. *) | ARROW_UP => app | ARROW_DOWN => app end