Scroll completions menu to new selection on filter, fix corner case (#23478)

In the future if `filter` was used more this would fix other issues. In
the current code paths, this just fixes the particular corner case of
edit prediction arriving async while `y_flipped = true` (in this case it
needs to be scrolled down to show item with index 0).

Release Notes:

- N/A
This commit is contained in:
Michael Sloan 2025-01-22 10:54:10 -07:00 committed by GitHub
parent 9f87145af9
commit 09fe1e7f66
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -865,18 +865,22 @@ impl CompletionsMenu {
drop(completions);
let mut entries = self.entries.borrow_mut();
if let Some(CompletionEntry::InlineCompletionHint(_)) = entries.first() {
let new_selection = if let Some(CompletionEntry::InlineCompletionHint(_)) = entries.first()
{
entries.truncate(1);
if inline_completion_was_selected || matches.is_empty() {
self.selected_item = 0;
0
} else {
self.selected_item = 1;
1
}
} else {
entries.truncate(0);
self.selected_item = 0;
}
0
};
entries.extend(matches.into_iter().map(CompletionEntry::Match));
self.selected_item = new_selection;
self.scroll_handle
.scroll_to_item(new_selection, ScrollStrategy::Top);
}
}