diff options
| author | Ogulcan Celik <ogulcancelik@gmail.com> | 2026-05-22 15:18:08 +0300 |
|---|---|---|
| committer | Ogulcan Celik <ogulcancelik@gmail.com> | 2026-05-22 15:18:08 +0300 |
| commit | 29fd06747b31e8ec7fbf32af662263040783b6c7 (patch) | |
| tree | f8dc493d02d15129ff22e1dcc6b8bc7350a95731 /src/config | |
| parent | 3c7c4464e5d46cf28036edbd98450baae768b823 (diff) | |
fix: accept unicode keybindings
refs #247
Diffstat (limited to 'src/config')
| -rw-r--r-- | src/config/keybinds.rs | 43 |
1 files changed, 41 insertions, 2 deletions
diff --git a/src/config/keybinds.rs b/src/config/keybinds.rs index edd64c90..014bab7a 100644 --- a/src/config/keybinds.rs +++ b/src/config/keybinds.rs @@ -820,6 +820,7 @@ pub(super) fn parse_key_combo(s: &str) -> Option<KeyCombo> { } let key_str = key_str?; + let single_char = single_key_char(key_str); let lower = key_str.to_lowercase(); let code = match lower.as_str() { "space" | " " => KeyCode::Char(' '), @@ -848,8 +849,8 @@ pub(super) fn parse_key_combo(s: &str) -> Option<KeyCombo> { "ampersand" => KeyCode::Char('&'), "backtick" => KeyCode::Char('`'), "plus" => KeyCode::Char('+'), - s if s.len() == 1 => { - let ch = key_str.chars().next().unwrap(); + _ if single_char.is_some() => { + let ch = single_char?; if ch.is_ascii_uppercase() { modifiers |= KeyModifiers::SHIFT; KeyCode::Char(ch.to_ascii_lowercase()) @@ -864,6 +865,16 @@ pub(super) fn parse_key_combo(s: &str) -> Option<KeyCombo> { Some(normalize_key_combo((code, modifiers))) } +fn single_key_char(s: &str) -> Option<char> { + let mut chars = s.chars(); + let ch = chars.next()?; + if chars.next().is_none() { + Some(ch) + } else { + None + } +} + fn parse_key_combo_with_diagnostic( s: &str, field: &str, @@ -1005,6 +1016,34 @@ mod tests { } #[test] + fn parse_unicode_char_combo() { + assert_eq!( + parse_key_combo("ö"), + Some((KeyCode::Char('ö'), KeyModifiers::empty())) + ); + assert_eq!( + parse_key_combo("alt+é"), + Some((KeyCode::Char('é'), KeyModifiers::ALT)) + ); + } + + #[test] + fn unicode_prefix_config_is_valid() { + let config: Config = toml::from_str( + r#" +[keys] +prefix = "ö" +"#, + ) + .unwrap(); + assert_eq!( + config.prefix_key(), + (KeyCode::Char('ö'), KeyModifiers::empty()) + ); + assert!(config.collect_diagnostics().is_empty()); + } + + #[test] fn parse_shift_tab_as_backtab() { assert_eq!( parse_key_combo("shift+tab"), |
