fix: empty candidate

This commit is contained in:
iff 2024-11-16 16:55:29 +01:00
parent 0177086dcc
commit 0e4e5d3714
2 changed files with 6 additions and 1 deletions

View file

@ -69,10 +69,12 @@ replace,
pattern = [ pattern = [
"did not match any file" "did not match any file"
] ]
# alternatively `git checkout {{typo[2]({{shell(git branch | sed 's/^*//')}})}}`
suggest = [ suggest = [
''' '''
#[cmd_contains(checkout)] #[cmd_contains(checkout)]
git checkout {{typo[2]({{shell(git branch)}})}} ''' git branch {{command[2]}} && \
git checkout {{command[2]}} '''
] ]
[[match_err]] [[match_err]]

View file

@ -171,6 +171,9 @@ pub fn find_similar(typo: &str, candidates: &Vec<String>) -> Option<String> {
let mut min_distance = 10; let mut min_distance = 10;
let mut min_distance_index = None; let mut min_distance_index = None;
for (i, candidate) in candidates.iter().enumerate() { for (i, candidate) in candidates.iter().enumerate() {
if candidate.is_empty() {
continue;
}
let distance = compare_string(typo, candidate); let distance = compare_string(typo, candidate);
if distance < min_distance { if distance < min_distance {
min_distance = distance; min_distance = distance;