From 31d157f1173dde459e09b0a9e8d0845267a47ceb Mon Sep 17 00:00:00 2001 From: Shou Ya Date: Sat, 9 Dec 2023 01:10:47 +0900 Subject: [PATCH] Disable redundant filtering in history pager Part of #10143 --- fish-rust/src/pager.rs | 14 +++++++++----- fish-rust/src/tests/pager.rs | 8 ++++---- src/reader.cpp | 4 ++-- 3 files changed, 15 insertions(+), 11 deletions(-) diff --git a/fish-rust/src/pager.rs b/fish-rust/src/pager.rs index 7bad74ecb..391d51a2a 100644 --- a/fish-rust/src/pager.rs +++ b/fish-rust/src/pager.rs @@ -582,7 +582,7 @@ impl Pager { } // Sets the set of completions. - pub fn set_completions(&mut self, raw_completions: &[Completion]) { + pub fn set_completions(&mut self, raw_completions: &[Completion], enable_refilter: bool) { self.selected_completion_idx = None; // Get completion infos out of it. self.unfiltered_completion_infos = process_completions_into_infos(raw_completions); @@ -596,7 +596,11 @@ impl Pager { self.measure_completion_infos(); // Refilter them. - self.refilter_completions(); + if enable_refilter { + self.refilter_completions(); + } else { + self.completion_infos = self.unfiltered_completion_infos.clone(); + } self.have_unrendered_completions = true; } @@ -1254,7 +1258,7 @@ mod pager_ffi { fn rendering_needs_update(&self, rendering: &PageRendering) -> bool; fn search_field_line(&mut self) -> *mut EditableLine; #[cxx_name = "set_completions"] - fn set_completions_ffi(&mut self, completions: &CompletionListFfi); + fn set_completions_ffi(&mut self, completions: &CompletionListFfi, enable_refilter: bool); fn set_fully_disclosed(&mut self); #[cxx_name = "set_prefix"] fn set_prefix_ffi(&mut self, prefix: &CxxWString, highlight: bool); @@ -1317,8 +1321,8 @@ impl Pager { fn set_extra_progress_text(&mut self, text: &CxxWString) { self.extra_progress_text = text.from_ffi(); } - fn set_completions_ffi(&mut self, completions: &CompletionListFfi) { - self.set_completions(&completions.0) + fn set_completions_ffi(&mut self, completions: &CompletionListFfi, enable_refilter: bool) { + self.set_completions(&completions.0, enable_refilter) } fn selected_completion_index_ffi(&self) -> usize { self.selected_completion_idx.unwrap_or(PAGER_SELECTION_NONE) diff --git a/fish-rust/src/tests/pager.rs b/fish-rust/src/tests/pager.rs index 080e065d7..57f35f3f9 100644 --- a/fish-rust/src/tests/pager.rs +++ b/fish-rust/src/tests/pager.rs @@ -24,7 +24,7 @@ add_test!("test_pager_navigation", || { } let mut pager = Pager::default(); - pager.set_completions(&completions); + pager.set_completions(&completions, true); pager.set_term_size(&Termsize::defaults()); let mut render = pager.render(); @@ -136,7 +136,7 @@ add_test!("test_pager_layout", || { StringFuzzyMatch::exact_match(), CompleteFlags::default(), )]; - pager.set_completions(&c1s); + pager.set_completions(&c1s, true); validate!(&mut pager, 26, L!("abcdefghij (1234567890)")); validate!(&mut pager, 25, L!("abcdefghij (1234567890)")); @@ -157,7 +157,7 @@ add_test!("test_pager_layout", || { StringFuzzyMatch::exact_match(), CompleteFlags::default(), )]; - pager.set_completions(&c2s); + pager.set_completions(&c2s, true); validate!(&mut pager, 26, L!("abcdefghijklmnopqrs (1)")); validate!(&mut pager, 25, L!("abcdefghijklmnopqrs (1)")); validate!(&mut pager, 24, L!("abcdefghijklmnopqrs (1)")); @@ -177,7 +177,7 @@ add_test!("test_pager_layout", || { StringFuzzyMatch::exact_match(), CompleteFlags::default(), )]; - pager.set_completions(&c3s); + pager.set_completions(&c3s, true); validate!(&mut pager, 26, L!("abcdefghijklmnopqrst")); validate!(&mut pager, 25, L!("abcdefghijklmnopqrst")); validate!(&mut pager, 24, L!("abcdefghijklmnopqrst")); diff --git a/src/reader.cpp b/src/reader.cpp index 5ca74d755..aa60466fd 100644 --- a/src/reader.cpp +++ b/src/reader.cpp @@ -1209,7 +1209,7 @@ void reader_data_t::fill_history_pager(history_pager_invocation_t why, } shared_this->pager.set_extra_progress_text( result.have_more_results ? _(L"Search again for more results") : L""); - shared_this->pager.set_completions(*result.matched_commands); + shared_this->pager.set_completions(*result.matched_commands, false); if (why == history_pager_invocation_t::Refresh) { pager.set_selected_completion_index(*old_pager_index); pager_selection_changed(); @@ -2290,7 +2290,7 @@ bool reader_data_t::handle_completions(const completion_list_t &comp, size_t tok // Update the pager data. pager.set_prefix(prefix, true); - pager.set_completions(surviving_completions); + pager.set_completions(surviving_completions, true); // Modify the command line to reflect the new pager. pager_selection_changed(); return false;