From 29fd06747b31e8ec7fbf32af662263040783b6c7 Mon Sep 17 00:00:00 2001 From: Ogulcan Celik Date: Fri, 22 May 2026 15:18:08 +0300 Subject: fix: accept unicode keybindings refs #247 --- src/config/keybinds.rs | 43 +++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 41 insertions(+), 2 deletions(-) (limited to 'src/config') 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 { } 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 { "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 { Some(normalize_key_combo((code, modifiers))) } +fn single_key_char(s: &str) -> Option { + 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, @@ -1004,6 +1015,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!( -- cgit v1.2.3