From 635bb4be554fc24425016750b689c9e859be0292 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E4=B8=89=E5=92=B2=E9=9B=85=20=C2=B7=20Misaki=20Masa?= Date: Wed, 18 Dec 2024 10:51:36 +0800 Subject: [PATCH] feat: allow `noop` for single-key chords by removing the mixing length limit (#2064) --- yazi-config/src/keymap/keymap.rs | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-) diff --git a/yazi-config/src/keymap/keymap.rs b/yazi-config/src/keymap/keymap.rs index a39dc6866..4639c0571 100644 --- a/yazi-config/src/keymap/keymap.rs +++ b/yazi-config/src/keymap/keymap.rs @@ -6,7 +6,7 @@ use serde::{Deserialize, Deserializer}; use yazi_shared::Layer; use super::Chord; -use crate::Preset; +use crate::{Preset, keymap::Key}; #[derive(Debug)] pub struct Keymap { @@ -72,17 +72,20 @@ impl<'de> Deserialize<'de> for Keymap { } fn mix(a: IndexSet, b: IndexSet, c: IndexSet) -> Vec { - let a_seen: HashSet<_> = - a.iter().filter(|&v| v.on.len() > 1).map(|v| [v.on[0], v.on[1]]).collect(); - let b_seen: HashSet<_> = - b.iter().filter(|&v| v.on.len() > 1).map(|v| [v.on[0], v.on[1]]).collect(); + #[inline] + fn on(Chord { on, .. }: &Chord) -> [Key; 2] { + [on.first().copied().unwrap_or_default(), on.get(1).copied().unwrap_or_default()] + } + + let a_seen: HashSet<_> = a.iter().map(on).collect(); + let b_seen: HashSet<_> = b.iter().map(on).collect(); Preset::mix( a, - b.into_iter().filter(|v| v.on.len() < 2 || !a_seen.contains(&v.on[..2])), - c.into_iter().filter(|v| v.on.len() < 2 || !b_seen.contains(&v.on[..2])), + b.into_iter().filter(|v| !a_seen.contains(&on(v))), + c.into_iter().filter(|v| !b_seen.contains(&on(v))), ) - .filter(|c| !c.noop()) + .filter(|chord| !chord.noop()) .collect() }