From f42eec5e8da9b37d6618a541ac28aea5591075c9 Mon Sep 17 00:00:00 2001 From: l0ng-ai <24760907+l0ng-ai@users.noreply.github.com> Date: Sun, 23 Aug 2026 09:57:07 +0800 Subject: [PATCH] test(keymap): hold the tmux preset to the same no-collision rule MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit A preset rebinds only the actions it names, so every default it leaves alone stays where it was — which is where a collision would come from, and it would only show up for the people who chose that preset. It is clean today. --- src/ui/keymap.rs | 45 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 45 insertions(+) diff --git a/src/ui/keymap.rs b/src/ui/keymap.rs index 55812816..d031c0fb 100644 --- a/src/ui/keymap.rs +++ b/src/ui/keymap.rs @@ -2302,4 +2302,49 @@ mod binding_conflicts { clashes.join("\n") ); } + + /// And the same holds once a preset has been laid over the defaults. + /// + /// A preset only rebinds the actions it names, so every default it does + /// *not* name stays where it was — which is exactly where a collision + /// would come from, and it would only appear for users who chose that + /// preset. Checked with the default prefix, which is what almost everyone + /// running the preset has. + #[test] + fn the_tmux_preset_does_not_collide_with_the_defaults_it_leaves_alone() { + let mut effective: Vec<(String, String)> = default_bindings() + .into_iter() + .map(|(a, k)| (a.to_string(), k.to_string())) + .collect(); + for (action, key) in preset_bindings("tmux", "") { + set_binding(&mut effective, &action, key); + } + + let mut claimed: HashMap<(String, Option<&str>), Vec> = HashMap::new(); + for (action, key) in &effective { + if key.is_empty() { + continue; + } + claimed + .entry((key.clone(), action_context(action))) + .or_default() + .push(action.clone()); + } + + let mut clashes: Vec = claimed + .into_iter() + .filter(|(_, actions)| actions.len() > 1) + .map(|((key, scope), actions)| { + format!("{key} in {}: {actions:?}", scope.unwrap_or("the window")) + }) + .collect(); + clashes.sort(); + + assert!( + clashes.is_empty(), + "under the tmux preset these share a key, so one of each pair never \ + fires:\n{}", + clashes.join("\n") + ); + } }