Skip to content

Commit

Permalink
fix: displaying duplicate command suggestions
Browse files Browse the repository at this point in the history
Fixes #955
  • Loading branch information
mikavilpas committed Apr 29, 2024
1 parent 3a09155 commit b862576
Showing 1 changed file with 16 additions and 8 deletions.
24 changes: 16 additions & 8 deletions yazi-core/src/which/commands/show.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use std::str::FromStr;
use std::{collections::HashMap, str::FromStr};

use yazi_config::{keymap::{Control, Key}, KEYMAP};
use yazi_config::{keymap::{Control, ControlCow, Key}, KEYMAP};
use yazi_shared::{event::Cmd, render, Layer};

use crate::which::{Which, WhichSorter};
Expand Down Expand Up @@ -45,16 +45,24 @@ impl Which {
pub fn show_with(&mut self, key: &Key, layer: Layer) {
self.layer = layer;
self.times = 1;
self.cands = KEYMAP
.get(layer)
.iter()
.filter(|c| c.on.len() > 1 && &c.on[0] == key)
.map(|c| c.into())
.collect();
self.cands = keymap_candidates(layer, key);

WhichSorter::default().sort(&mut self.cands);
self.visible = true;
self.silent = false;
render!();
}
}

fn keymap_candidates(layer: Layer, key: &Key) -> Vec<ControlCow> {
let mut results: HashMap<&Vec<Key>, ControlCow> = HashMap::new();

let matches = KEYMAP.get(layer).iter().filter(|c| c.on.len() > 1 && &c.on[0] == key);
for c in matches {
if !results.contains_key(&c.on) {
results.insert(&c.on, c.into());
}
}

results.into_values().collect()
}

0 comments on commit b862576

Please sign in to comment.