Highlight fuzzy match positions in command palette
This commit is contained in:
parent
3bbc021a7e
commit
f5377c2f50
1 changed files with 27 additions and 10 deletions
|
@ -135,7 +135,19 @@ impl PickerDelegate for CommandPalette {
|
||||||
})
|
})
|
||||||
.collect::<Vec<_>>();
|
.collect::<Vec<_>>();
|
||||||
cx.spawn(move |this, mut cx| async move {
|
cx.spawn(move |this, mut cx| async move {
|
||||||
let matches = fuzzy::match_strings(
|
let matches = if query.is_empty() {
|
||||||
|
candidates
|
||||||
|
.into_iter()
|
||||||
|
.enumerate()
|
||||||
|
.map(|(index, candidate)| StringMatch {
|
||||||
|
candidate_id: index,
|
||||||
|
string: candidate.string,
|
||||||
|
positions: Vec::new(),
|
||||||
|
score: 0.0,
|
||||||
|
})
|
||||||
|
.collect()
|
||||||
|
} else {
|
||||||
|
fuzzy::match_strings(
|
||||||
&candidates,
|
&candidates,
|
||||||
&query,
|
&query,
|
||||||
true,
|
true,
|
||||||
|
@ -143,7 +155,8 @@ impl PickerDelegate for CommandPalette {
|
||||||
&Default::default(),
|
&Default::default(),
|
||||||
cx.background(),
|
cx.background(),
|
||||||
)
|
)
|
||||||
.await;
|
.await
|
||||||
|
};
|
||||||
this.update(&mut cx, |this, _| {
|
this.update(&mut cx, |this, _| {
|
||||||
this.matches = matches;
|
this.matches = matches;
|
||||||
if this.matches.is_empty() {
|
if this.matches.is_empty() {
|
||||||
|
@ -186,7 +199,11 @@ impl PickerDelegate for CommandPalette {
|
||||||
let keystroke_spacing = theme.command_palette.keystroke_spacing;
|
let keystroke_spacing = theme.command_palette.keystroke_spacing;
|
||||||
|
|
||||||
Flex::row()
|
Flex::row()
|
||||||
.with_child(Label::new(mat.string.clone(), style.label.clone()).boxed())
|
.with_child(
|
||||||
|
Label::new(mat.string.clone(), style.label.clone())
|
||||||
|
.with_highlights(mat.positions.clone())
|
||||||
|
.boxed(),
|
||||||
|
)
|
||||||
.with_children(command.keystrokes.iter().map(|keystroke| {
|
.with_children(command.keystrokes.iter().map(|keystroke| {
|
||||||
Flex::row()
|
Flex::row()
|
||||||
.with_children(
|
.with_children(
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue