Update command matches faster
This commit is contained in:
parent
ca3341f066
commit
abdaa3105b
2 changed files with 7 additions and 14 deletions
|
@ -130,16 +130,7 @@ impl CommandPaletteDelegate {
|
||||||
) -> Self {
|
) -> Self {
|
||||||
Self {
|
Self {
|
||||||
command_palette,
|
command_palette,
|
||||||
matches: commands
|
matches: vec![],
|
||||||
.iter()
|
|
||||||
.enumerate()
|
|
||||||
.map(|(i, command)| StringMatch {
|
|
||||||
candidate_id: i,
|
|
||||||
string: command.name.clone(),
|
|
||||||
positions: Vec::new(),
|
|
||||||
score: 0.0,
|
|
||||||
})
|
|
||||||
.collect(),
|
|
||||||
commands,
|
commands,
|
||||||
selected_ix: 0,
|
selected_ix: 0,
|
||||||
previous_focus_handle,
|
previous_focus_handle,
|
||||||
|
|
|
@ -10,7 +10,7 @@ pub struct Picker<D: PickerDelegate> {
|
||||||
pub delegate: D,
|
pub delegate: D,
|
||||||
scroll_handle: UniformListScrollHandle,
|
scroll_handle: UniformListScrollHandle,
|
||||||
editor: View<Editor>,
|
editor: View<Editor>,
|
||||||
pending_update_matches: Option<Task<Option<()>>>,
|
pending_update_matches: Option<Task<()>>,
|
||||||
}
|
}
|
||||||
|
|
||||||
pub trait PickerDelegate: Sized + 'static {
|
pub trait PickerDelegate: Sized + 'static {
|
||||||
|
@ -42,12 +42,14 @@ impl<D: PickerDelegate> Picker<D> {
|
||||||
editor
|
editor
|
||||||
});
|
});
|
||||||
cx.subscribe(&editor, Self::on_input_editor_event).detach();
|
cx.subscribe(&editor, Self::on_input_editor_event).detach();
|
||||||
Self {
|
let mut this = Self {
|
||||||
delegate,
|
delegate,
|
||||||
scroll_handle: UniformListScrollHandle::new(),
|
scroll_handle: UniformListScrollHandle::new(),
|
||||||
pending_update_matches: None,
|
pending_update_matches: None,
|
||||||
editor,
|
editor,
|
||||||
}
|
};
|
||||||
|
this.update_matches("".to_string(), cx);
|
||||||
|
this
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn focus(&self, cx: &mut WindowContext) {
|
pub fn focus(&self, cx: &mut WindowContext) {
|
||||||
|
@ -126,7 +128,7 @@ impl<D: PickerDelegate> Picker<D> {
|
||||||
this.update(&mut cx, |this, cx| {
|
this.update(&mut cx, |this, cx| {
|
||||||
this.matches_updated(cx);
|
this.matches_updated(cx);
|
||||||
})
|
})
|
||||||
.ok()
|
.ok();
|
||||||
}));
|
}));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue