Merge pull request #151 from Cooper-X-Oak/codex/issue-148-qa-hotkey-normalization
fix(windows): 归一 QA hotkey 的跨平台修饰键语义
This commit is contained in:
1 file changed
+32
-1
@@ -173,7 +173,7 @@ fn forward_loop(
|
||||
fn parse_binding(binding: &QaHotkeyBinding) -> Result<HotKey, QaHotkeyError> {
|
||||
let mut mods = Modifiers::empty();
|
||||
for raw in &binding.modifiers {
|
||||
let tag = raw.trim().to_ascii_lowercase();
|
||||
let tag = normalize_modifier_tag(raw);
|
||||
let bit = match tag.as_str() {
|
||||
"cmd" | "command" | "super" | "meta" | "win" => Modifiers::SUPER,
|
||||
"ctrl" | "control" => Modifiers::CONTROL,
|
||||
@@ -187,6 +187,17 @@ fn parse_binding(binding: &QaHotkeyBinding) -> Result<HotKey, QaHotkeyError> {
|
||||
Ok(HotKey::new(Some(mods), code))
|
||||
}
|
||||
|
||||
fn normalize_modifier_tag(raw: &str) -> String {
|
||||
let tag = raw.trim().to_ascii_lowercase();
|
||||
#[cfg(target_os = "windows")]
|
||||
{
|
||||
if matches!(tag.as_str(), "cmd" | "command") {
|
||||
return "ctrl".to_string();
|
||||
}
|
||||
}
|
||||
tag
|
||||
}
|
||||
|
||||
/// 把用户配置的主键字符串解析成 keyboard_types::Code。
|
||||
/// 支持单字符(字母 / 数字 / 符号)+ 常见命名键(F1..F12 / Enter / Tab / Escape / Space)。
|
||||
fn parse_primary(raw: &str) -> Result<Code, QaHotkeyError> {
|
||||
@@ -339,4 +350,24 @@ mod tests {
|
||||
Err(QaHotkeyError::UnsupportedKey(_))
|
||||
));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn cmd_modifier_normalizes_per_platform() {
|
||||
let binding = QaHotkeyBinding {
|
||||
primary: ";".into(),
|
||||
modifiers: vec!["cmd".into(), "shift".into()],
|
||||
};
|
||||
let parsed = parse_binding(&binding).expect("binding parses");
|
||||
|
||||
#[cfg(target_os = "windows")]
|
||||
{
|
||||
assert!(parsed.mods.contains(Modifiers::CONTROL));
|
||||
assert!(!parsed.mods.contains(Modifiers::SUPER));
|
||||
}
|
||||
|
||||
#[cfg(not(target_os = "windows"))]
|
||||
{
|
||||
assert!(parsed.mods.contains(Modifiers::SUPER));
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user