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

This commit is contained in:
2025-08-07 15:37:32 +01:00
parent 27c5d11dd7
commit 73affaa83a
2 changed files with 45 additions and 13 deletions

View File

@@ -388,11 +388,16 @@ struct
fun helpRemoveChr (app: app_type, buffer, cursorIdx, count) = fun helpRemoveChr (app: app_type, buffer, cursorIdx, count) =
if count = 0 then if count = 0 then
let let
val searchString = #searchString app
val buffer = LineGap.goToEnd buffer 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 in
Finish.buildTextAndClear Finish.buildTextAndClear
(app, buffer, cursorIdx, SearchList.empty, initialMsg) (app, buffer, cursorIdx, searchList, initialMsg)
end end
else else
let let
@@ -468,6 +473,10 @@ struct
val searchString = #searchString app val searchString = #searchString app
val initialMsg = [SEARCH (buffer, searchString)] 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 (* If we have deleted from the buffer so that cursorIdx
* is no longer a valid idx, * is no longer a valid idx,
* clip cursorIdx to the end. *) * clip cursorIdx to the end. *)
@@ -475,7 +484,7 @@ struct
val cursorIdx = Cursor.clipIdx (buffer, low) val cursorIdx = Cursor.clipIdx (buffer, low)
in in
Finish.buildTextAndClear Finish.buildTextAndClear
(app, buffer, cursorIdx, SearchList.empty, initialMsg) (app, buffer, cursorIdx, searchList, initialMsg)
end end
else else
let let
@@ -506,9 +515,13 @@ struct
val buffer = LineGap.goToEnd buffer val buffer = LineGap.goToEnd buffer
val initialMsg = [SEARCH (buffer, searchString)] 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) val buffer = LineGap.goToIdx (low, buffer)
in in
Finish.buildTextAndClear (app, buffer, low, SearchList.empty, initialMsg) Finish.buildTextAndClear (app, buffer, low, searchList, initialMsg)
end end
fun deleteToEndOfLine (app: app_type) = fun deleteToEndOfLine (app: app_type) =
@@ -549,10 +562,13 @@ struct
val buffer = LineGap.goToEnd buffer val buffer = LineGap.goToEnd buffer
val initialMsg = [SEARCH (buffer, searchString)] 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) val buffer = LineGap.goToIdx (startIdx, buffer)
in in
Finish.buildTextAndClear Finish.buildTextAndClear (app, buffer, startIdx, searchList, initialMsg)
(app, buffer, startIdx, SearchList.empty, initialMsg)
end end
fun helpDeleteLineBack (app, buffer, low, high, count) = fun helpDeleteLineBack (app, buffer, low, high, count) =
@@ -566,10 +582,12 @@ struct
val searchString = #searchString app val searchString = #searchString app
val initialMsg = [SEARCH (buffer, searchString)] 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) val buffer = LineGap.goToIdx (low, buffer)
in in
Finish.buildTextAndClear Finish.buildTextAndClear (app, buffer, low, searchList, initialMsg)
(app, buffer, low, SearchList.empty, initialMsg)
end end
else else
let let
@@ -619,8 +637,12 @@ struct
val buffer = LineGap.goToEnd buffer val buffer = LineGap.goToEnd buffer
val initialMsg = [SEARCH (buffer, searchString)] val initialMsg = [SEARCH (buffer, searchString)]
val buffer = LineGap.goToIdx (cursorIdx + 777, buffer)
val searchList =
SearchList.buildRange (buffer, searchString, cursorIdx - 777)
in in
Finish.buildTextAndClear (app, buffer, low, SearchList.empty, initialMsg) Finish.buildTextAndClear (app, buffer, low, searchList, initialMsg)
end end
fun helpDeleteToChr fun helpDeleteToChr
@@ -635,9 +657,12 @@ struct
val buffer = LineGap.goToEnd buffer val buffer = LineGap.goToEnd buffer
val searchString = #searchString app val searchString = #searchString app
val initialMsg = [SEARCH (buffer, searchString)] val initialMsg = [SEARCH (buffer, searchString)]
val buffer = LineGap.goToIdx (cursorIdx + 777, buffer)
val searchList =
SearchList.buildRange (buffer, searchString, cursorIdx - 777)
in in
buildTextAndClearAfterChr buildTextAndClearAfterChr (app, buffer, low, searchList, initialMsg)
(app, buffer, low, SearchList.empty, initialMsg)
end end
else else
let let
@@ -668,11 +693,14 @@ struct
app app
val buffer = LineGap.delete (0, cursorIdx, buffer) val buffer = LineGap.delete (0, cursorIdx, buffer)
val searchList = SearchList.empty
val buffer = LineGap.goToEnd buffer val buffer = LineGap.goToEnd buffer
val initialMsg = [SEARCH (buffer, #searchString app)] 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 cursorIdx = 0
val startLine = 0 val startLine = 0
val buffer = LineGap.goToIdx (cursorIdx, buffer) val buffer = LineGap.goToIdx (cursorIdx, buffer)
@@ -703,9 +731,12 @@ struct
val buffer = LineGap.goToEnd buffer val buffer = LineGap.goToEnd buffer
val initialMsg = [SEARCH (buffer, searchString)] 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) val buffer = LineGap.goToIdx (low, buffer)
in in
Finish.buildTextAndClear (app, buffer, low, SearchList.empty, initialMsg) Finish.buildTextAndClear (app, buffer, low, searchList, initialMsg)
end end
fun deleteToNextMatch (app: app_type, count) = fun deleteToNextMatch (app: app_type, count) =

View File

@@ -159,6 +159,7 @@ struct
fun searchRange (buffer: LineGap.t, searchString, low) = fun searchRange (buffer: LineGap.t, searchString, low) =
let let
val low = Int.max (low, 0)
val {rightStrings, leftStrings, idx = absIdx, ...} = buffer val {rightStrings, leftStrings, idx = absIdx, ...} = buffer
in in
case rightStrings of case rightStrings of