From 73affaa83a5c440437c9c9891265b8f959a0f497 Mon Sep 17 00:00:00 2001 From: Humza Shahid Date: Thu, 7 Aug 2025 15:37:32 +0100 Subject: [PATCH] instead of clearing the search list when we delete, build a small part of it by searching through a small part that is likely to be visible on the user's screen, which gets rid of flickering effect and makes it look like the search list is not rebuilt from scratch --- fcore/app-update.sml | 57 +++++++++++++++++++++++++++++++++---------- fcore/search-list.sml | 1 + 2 files changed, 45 insertions(+), 13 deletions(-) diff --git a/fcore/app-update.sml b/fcore/app-update.sml index b4e7a20..8f6635b 100644 --- a/fcore/app-update.sml +++ b/fcore/app-update.sml @@ -388,11 +388,16 @@ struct fun helpRemoveChr (app: app_type, buffer, cursorIdx, count) = if count = 0 then let + val searchString = #searchString app val buffer = LineGap.goToEnd buffer - val initialMsg = [SEARCH (buffer, #searchString app)] + val initialMsg = [SEARCH (buffer, searchString)] + + val buffer = LineGap.goToIdx (cursorIdx + 777, buffer) + val searchList = + SearchList.buildRange (buffer, searchString, cursorIdx - 777) in Finish.buildTextAndClear - (app, buffer, cursorIdx, SearchList.empty, initialMsg) + (app, buffer, cursorIdx, searchList, initialMsg) end else let @@ -468,6 +473,10 @@ struct val searchString = #searchString app val initialMsg = [SEARCH (buffer, searchString)] + val buffer = LineGap.goToIdx (cursorIdx + 777, buffer) + val searchList = + SearchList.buildRange (buffer, searchString, cursorIdx - 777) + (* If we have deleted from the buffer so that cursorIdx * is no longer a valid idx, * clip cursorIdx to the end. *) @@ -475,7 +484,7 @@ struct val cursorIdx = Cursor.clipIdx (buffer, low) in Finish.buildTextAndClear - (app, buffer, cursorIdx, SearchList.empty, initialMsg) + (app, buffer, cursorIdx, searchList, initialMsg) end else let @@ -506,9 +515,13 @@ struct val buffer = LineGap.goToEnd buffer val initialMsg = [SEARCH (buffer, searchString)] + val buffer = LineGap.goToIdx (cursorIdx + 777, buffer) + val searchList = + SearchList.buildRange (buffer, searchString, cursorIdx - 777) + val buffer = LineGap.goToIdx (low, buffer) in - Finish.buildTextAndClear (app, buffer, low, SearchList.empty, initialMsg) + Finish.buildTextAndClear (app, buffer, low, searchList, initialMsg) end fun deleteToEndOfLine (app: app_type) = @@ -549,10 +562,13 @@ struct val buffer = LineGap.goToEnd buffer val initialMsg = [SEARCH (buffer, searchString)] + val buffer = LineGap.goToIdx (cursorIdx + 777, buffer) + val searchList = + SearchList.buildRange (buffer, searchString, cursorIdx - 777) + val buffer = LineGap.goToIdx (startIdx, buffer) in - Finish.buildTextAndClear - (app, buffer, startIdx, SearchList.empty, initialMsg) + Finish.buildTextAndClear (app, buffer, startIdx, searchList, initialMsg) end fun helpDeleteLineBack (app, buffer, low, high, count) = @@ -566,10 +582,12 @@ struct val searchString = #searchString app val initialMsg = [SEARCH (buffer, searchString)] + val buffer = LineGap.goToIdx (low + 777, buffer) + val searchList = SearchList.buildRange (buffer, searchString, low - 777) + val buffer = LineGap.goToIdx (low, buffer) in - Finish.buildTextAndClear - (app, buffer, low, SearchList.empty, initialMsg) + Finish.buildTextAndClear (app, buffer, low, searchList, initialMsg) end else let @@ -619,8 +637,12 @@ struct val buffer = LineGap.goToEnd buffer val initialMsg = [SEARCH (buffer, searchString)] + + val buffer = LineGap.goToIdx (cursorIdx + 777, buffer) + val searchList = + SearchList.buildRange (buffer, searchString, cursorIdx - 777) in - Finish.buildTextAndClear (app, buffer, low, SearchList.empty, initialMsg) + Finish.buildTextAndClear (app, buffer, low, searchList, initialMsg) end fun helpDeleteToChr @@ -635,9 +657,12 @@ struct val buffer = LineGap.goToEnd buffer val searchString = #searchString app val initialMsg = [SEARCH (buffer, searchString)] + + val buffer = LineGap.goToIdx (cursorIdx + 777, buffer) + val searchList = + SearchList.buildRange (buffer, searchString, cursorIdx - 777) in - buildTextAndClearAfterChr - (app, buffer, low, SearchList.empty, initialMsg) + buildTextAndClearAfterChr (app, buffer, low, searchList, initialMsg) end else let @@ -668,11 +693,14 @@ struct app val buffer = LineGap.delete (0, cursorIdx, buffer) - val searchList = SearchList.empty val buffer = LineGap.goToEnd buffer val initialMsg = [SEARCH (buffer, #searchString app)] + val buffer = LineGap.goToIdx (cursorIdx + 777, buffer) + val searchList = + SearchList.buildRange (buffer, searchString, cursorIdx - 777) + val cursorIdx = 0 val startLine = 0 val buffer = LineGap.goToIdx (cursorIdx, buffer) @@ -703,9 +731,12 @@ struct val buffer = LineGap.goToEnd buffer val initialMsg = [SEARCH (buffer, searchString)] + val buffer = LineGap.goToIdx (low + 777, buffer) + val searchList = SearchList.buildRange (buffer, searchString, low - 777) + val buffer = LineGap.goToIdx (low, buffer) in - Finish.buildTextAndClear (app, buffer, low, SearchList.empty, initialMsg) + Finish.buildTextAndClear (app, buffer, low, searchList, initialMsg) end fun deleteToNextMatch (app: app_type, count) = diff --git a/fcore/search-list.sml b/fcore/search-list.sml index 61523ae..c48cab0 100644 --- a/fcore/search-list.sml +++ b/fcore/search-list.sml @@ -159,6 +159,7 @@ struct fun searchRange (buffer: LineGap.t, searchString, low) = let + val low = Int.max (low, 0) val {rightStrings, leftStrings, idx = absIdx, ...} = buffer in case rightStrings of