mirror of
https://github.com/sxyazi/yazi.git
synced 2026-07-25 08:41:05 +00:00
fix: prefix matching should have high priority in completion
This commit is contained in:
parent
1bbb323509
commit
af7377aab4
1 changed files with 28 additions and 6 deletions
|
|
@ -36,21 +36,43 @@ impl Completion {
|
||||||
return false;
|
return false;
|
||||||
};
|
};
|
||||||
|
|
||||||
let flow = cache.iter().try_fold(Vec::with_capacity(30), |mut v, s| {
|
let candidate_size = 30;
|
||||||
if s.contains(opt.word) && s != opt.word {
|
|
||||||
|
// prioritize those with exact prefix
|
||||||
|
let exact_flow = cache.iter().try_fold(Vec::with_capacity(candidate_size), |mut v, s| {
|
||||||
|
if s.starts_with(opt.word) && s != opt.word {
|
||||||
v.push(s.to_owned());
|
v.push(s.to_owned());
|
||||||
if v.len() >= 30 {
|
if v.len() >= candidate_size {
|
||||||
return ControlFlow::Break(v);
|
return ControlFlow::Break(v);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
ControlFlow::Continue(v)
|
ControlFlow::Continue(v)
|
||||||
});
|
});
|
||||||
|
let mut cand = match exact_flow {
|
||||||
self.ticket = opt.ticket;
|
|
||||||
self.cands = match flow {
|
|
||||||
ControlFlow::Continue(v) => v,
|
ControlFlow::Continue(v) => v,
|
||||||
ControlFlow::Break(v) => v,
|
ControlFlow::Break(v) => v,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
let fuzzy_flow =
|
||||||
|
cache.iter().try_fold(Vec::with_capacity(candidate_size - cand.len()), |mut v, s| {
|
||||||
|
if s.contains(opt.word) && !s.starts_with(opt.word) && s != opt.word {
|
||||||
|
v.push(s.to_owned());
|
||||||
|
if v.len() >= candidate_size - cand.len() {
|
||||||
|
return ControlFlow::Break(v);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
ControlFlow::Continue(v)
|
||||||
|
});
|
||||||
|
cand.extend(
|
||||||
|
match fuzzy_flow {
|
||||||
|
ControlFlow::Continue(v) => v,
|
||||||
|
ControlFlow::Break(v) => v,
|
||||||
|
}
|
||||||
|
.into_iter(),
|
||||||
|
);
|
||||||
|
|
||||||
|
self.ticket = opt.ticket;
|
||||||
|
self.cands = cand;
|
||||||
if self.cands.is_empty() {
|
if self.cands.is_empty() {
|
||||||
return mem::replace(&mut self.visible, false);
|
return mem::replace(&mut self.visible, false);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue