From e58f77810c1373634923b118feee41aa131d3fe0 Mon Sep 17 00:00:00 2001 From: Steve Date: Fri, 30 Oct 2026 11:24:41 +0530 Subject: [PATCH] show all modifiers in key hints --- CHANGELOG.md | 1 + src/keys/key_config.rs | 39 +++++++++++++++++++++++++++++---------- 2 files changed, 30 insertions(+), 10 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index a1ca0eaac2..5b2105ae64 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -20,6 +20,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 * crash when opening submodule ([#2895](https://github.com/gitui-org/gitui/issues/2895)) * when staging the last file in a directory, the first item after the directory is no longer skipped [[@Tillerino](https://github.com/Tillerino)] ([#2748](https://github.com/gitui-org/gitui/issues/2748)) * index-out-of-bounds panic when unstaging lines near the end of a diff ([#2953](https://github.com/gitui-org/gitui/issues/2953)) +* key hints now show every modifier of a binding such as `ctrl+shift` instead of dropping them ## [0.28.1] - 2026-03-21 diff --git a/src/keys/key_config.rs b/src/keys/key_config.rs index 45a9ffdfb2..3c282bee64 100644 --- a/src/keys/key_config.rs +++ b/src/keys/key_config.rs @@ -111,20 +111,21 @@ impl KeyConfig { u ) } - KeyCode::Null => { - self.get_modifier_hint(ev.modifiers).into() - } + KeyCode::Null => self.get_modifier_hint(ev.modifiers), _ => String::new(), } } - fn get_modifier_hint(&self, modifier: KeyModifiers) -> &str { - match modifier { - KeyModifiers::CONTROL => &self.symbols.control, - KeyModifiers::SHIFT => &self.symbols.shift, - KeyModifiers::ALT => &self.symbols.alt, - _ => "", - } + fn get_modifier_hint(&self, modifier: KeyModifiers) -> String { + [ + (KeyModifiers::CONTROL, &self.symbols.control), + (KeyModifiers::SHIFT, &self.symbols.shift), + (KeyModifiers::ALT, &self.symbols.alt), + ] + .into_iter() + .filter(|(flag, _)| modifier.contains(*flag)) + .map(|(_, symbol)| symbol.as_str()) + .collect() } } @@ -145,6 +146,24 @@ mod tests { assert_eq!(h, "^c"); } + #[test] + fn test_get_hint_combined_modifiers() { + let config = KeyConfig::default(); + let h = config.get_hint(GituiKeyEvent::new( + KeyCode::Char('c'), + KeyModifiers::CONTROL | KeyModifiers::SHIFT, + )); + assert_eq!(h, "^\u{21e7}c"); + + let h = config.get_hint(GituiKeyEvent::new( + KeyCode::Up, + KeyModifiers::CONTROL + | KeyModifiers::SHIFT + | KeyModifiers::ALT, + )); + assert_eq!(h, "^\u{21e7}\u{2325}\u{2191}"); + } + #[test] fn test_symbolic_links() { let app_home = get_app_config_path().unwrap();