pager: Simplify some code

This commit is contained in:
Fabian Boehm 2024-02-28 18:26:26 +01:00
parent 31c2eb3f3c
commit 3d1e8a6106

View file

@ -636,17 +636,11 @@ impl Pager {
None => { None => {
// Handle the case of nothing selected yet. // Handle the case of nothing selected yet.
match direction { match direction {
SelectionMotion::South SelectionMotion::South | SelectionMotion::PageSouth | SelectionMotion::Next => {
| SelectionMotion::PageSouth self.selected_completion_idx = Some(0)
| SelectionMotion::Next }
| SelectionMotion::North SelectionMotion::North | SelectionMotion::Prev => {
| SelectionMotion::Prev => { self.selected_completion_idx = Some(self.completion_infos.len() - 1)
// These directions do something sane.
if matches!(direction, SelectionMotion::Prev | SelectionMotion::North) {
self.selected_completion_idx = Some(self.completion_infos.len() - 1);
} else {
self.selected_completion_idx = Some(0);
}
} }
SelectionMotion::East SelectionMotion::East
| SelectionMotion::West | SelectionMotion::West
@ -967,10 +961,9 @@ impl Pager {
// Updates the completions list per the filter. // Updates the completions list per the filter.
pub fn refilter_completions(&mut self) { pub fn refilter_completions(&mut self) {
self.completion_infos.clear(); self.completion_infos.clear();
for i in 0..self.unfiltered_completion_infos.len() { for comp in &self.unfiltered_completion_infos {
if self.completion_info_passes_filter(&self.unfiltered_completion_infos[i]) { if self.completion_info_passes_filter(comp) {
self.completion_infos self.completion_infos.push(comp.clone());
.push(self.unfiltered_completion_infos[i].clone());
} }
} }
} }