mirror of
https://github.com/zed-industries/zed.git
synced 2024-11-08 07:35:01 +03:00
Highlight fuzzy match positions in command palette
This commit is contained in:
parent
3bbc021a7e
commit
f5377c2f50
@ -135,15 +135,28 @@ 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,
|
candidates
|
||||||
&query,
|
.into_iter()
|
||||||
true,
|
.enumerate()
|
||||||
10000,
|
.map(|(index, candidate)| StringMatch {
|
||||||
&Default::default(),
|
candidate_id: index,
|
||||||
cx.background(),
|
string: candidate.string,
|
||||||
)
|
positions: Vec::new(),
|
||||||
.await;
|
score: 0.0,
|
||||||
|
})
|
||||||
|
.collect()
|
||||||
|
} else {
|
||||||
|
fuzzy::match_strings(
|
||||||
|
&candidates,
|
||||||
|
&query,
|
||||||
|
true,
|
||||||
|
10000,
|
||||||
|
&Default::default(),
|
||||||
|
cx.background(),
|
||||||
|
)
|
||||||
|
.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…
Reference in New Issue
Block a user