diff options
author | Michael Davis | 2022-12-07 22:27:31 +0000 |
---|---|---|
committer | Blaž Hrastnik | 2022-12-15 08:52:44 +0000 |
commit | a7daa02346789e43af51db2b944b0dc516354a29 (patch) | |
tree | 32cc3b81839fa38dfe62937637e8f3a48548976f | |
parent | d1f717eb8d02205ce224292f157bfe1bddd1f6db (diff) |
DynamicPicker: Use idle-timeout as debounce
This change uses the idle-timeout event to trigger fetching new results
in the DynamicPicker, so idle-timeout becomes a sort of debounce. This
prevents querying the language server overly aggressively.
-rw-r--r-- | helix-term/src/ui/picker.rs | 7 |
1 files changed, 5 insertions, 2 deletions
diff --git a/helix-term/src/ui/picker.rs b/helix-term/src/ui/picker.rs index 821a282c..35597843 100644 --- a/helix-term/src/ui/picker.rs +++ b/helix-term/src/ui/picker.rs @@ -763,6 +763,7 @@ pub type DynQueryCallback<T> = pub struct DynamicPicker<T: ui::menu::Item + Send> { file_picker: FilePicker<T>, query_callback: DynQueryCallback<T>, + query: String, } impl<T: ui::menu::Item + Send> DynamicPicker<T> { @@ -772,6 +773,7 @@ impl<T: ui::menu::Item + Send> DynamicPicker<T> { Self { file_picker, query_callback, + query: String::new(), } } } @@ -782,14 +784,15 @@ impl<T: Item + Send + 'static> Component for DynamicPicker<T> { } fn handle_event(&mut self, event: &Event, cx: &mut Context) -> EventResult { - let prev_query = self.file_picker.picker.prompt.line().to_owned(); let event_result = self.file_picker.handle_event(event, cx); let current_query = self.file_picker.picker.prompt.line(); - if *current_query == prev_query || matches!(event_result, EventResult::Ignored(_)) { + if !matches!(event, Event::IdleTimeout) || self.query == *current_query { return event_result; } + self.query.clone_from(current_query); + let new_options = (self.query_callback)(current_query.to_owned(), cx.editor); cx.jobs.callback(async move { |