mirror of
https://github.com/helix-editor/helix.git
synced 2024-11-22 17:36:19 +04:00
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.
This commit is contained in:
parent
d1f717eb8d
commit
a7daa02346
@ -763,6 +763,7 @@ fn cursor(&self, area: Rect, editor: &Editor) -> (Option<Position>, CursorKind)
|
|||||||
pub struct DynamicPicker<T: ui::menu::Item + Send> {
|
pub struct DynamicPicker<T: ui::menu::Item + Send> {
|
||||||
file_picker: FilePicker<T>,
|
file_picker: FilePicker<T>,
|
||||||
query_callback: DynQueryCallback<T>,
|
query_callback: DynQueryCallback<T>,
|
||||||
|
query: String,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<T: ui::menu::Item + Send> DynamicPicker<T> {
|
impl<T: ui::menu::Item + Send> DynamicPicker<T> {
|
||||||
@ -772,6 +773,7 @@ pub fn new(file_picker: FilePicker<T>, query_callback: DynQueryCallback<T>) -> S
|
|||||||
Self {
|
Self {
|
||||||
file_picker,
|
file_picker,
|
||||||
query_callback,
|
query_callback,
|
||||||
|
query: String::new(),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -782,14 +784,15 @@ fn render(&mut self, area: Rect, surface: &mut Surface, cx: &mut Context) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn handle_event(&mut self, event: &Event, cx: &mut Context) -> EventResult {
|
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 event_result = self.file_picker.handle_event(event, cx);
|
||||||
let current_query = self.file_picker.picker.prompt.line();
|
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;
|
return event_result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
self.query.clone_from(current_query);
|
||||||
|
|
||||||
let new_options = (self.query_callback)(current_query.to_owned(), cx.editor);
|
let new_options = (self.query_callback)(current_query.to_owned(), cx.editor);
|
||||||
|
|
||||||
cx.jobs.callback(async move {
|
cx.jobs.callback(async move {
|
||||||
|
Loading…
Reference in New Issue
Block a user