mirror of
https://github.com/RGBCube/serenity
synced 2025-06-01 09:58:14 +00:00
Assistant: Remember currently selected result when updating results
This fixes an issue where the selected result index would be reset to 0 when the file cache finished building and the results list updated.
This commit is contained in:
parent
3ee12ffa8f
commit
55f4d468ad
1 changed files with 10 additions and 2 deletions
|
@ -262,10 +262,18 @@ ErrorOr<int> serenity_main(Main::Arguments arguments)
|
|||
}));
|
||||
|
||||
db.on_new_results = [&](auto results) {
|
||||
if (results.is_empty())
|
||||
if (results.is_empty()) {
|
||||
app_state.selected_index = {};
|
||||
else
|
||||
} else if (app_state.selected_index.has_value()) {
|
||||
auto current_selected_result = app_state.results[app_state.selected_index.value()];
|
||||
auto new_selected_index = results.find_first_index(current_selected_result).value_or(0);
|
||||
if (new_selected_index >= Assistant::MAX_SEARCH_RESULTS) {
|
||||
new_selected_index = 0;
|
||||
}
|
||||
app_state.selected_index = new_selected_index;
|
||||
} else {
|
||||
app_state.selected_index = 0;
|
||||
}
|
||||
app_state.results = results;
|
||||
app_state.visible_result_count = min(results.size(), Assistant::MAX_SEARCH_RESULTS);
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue