Skip to content

Commit c8bb089

Browse files
authored
Merge pull request #151 from Cooper-X-Oak/codex/issue-148-qa-hotkey-normalization
fix(windows): 归一 QA hotkey 的跨平台修饰键语义
2 parents cc030c8 + a758cfa commit c8bb089

1 file changed

Lines changed: 32 additions & 1 deletion

File tree

openless-all/app/src-tauri/src/qa_hotkey.rs

Lines changed: 32 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -173,7 +173,7 @@ fn forward_loop(
173173
fn parse_binding(binding: &QaHotkeyBinding) -> Result<HotKey, QaHotkeyError> {
174174
let mut mods = Modifiers::empty();
175175
for raw in &binding.modifiers {
176-
let tag = raw.trim().to_ascii_lowercase();
176+
let tag = normalize_modifier_tag(raw);
177177
let bit = match tag.as_str() {
178178
"cmd" | "command" | "super" | "meta" | "win" => Modifiers::SUPER,
179179
"ctrl" | "control" => Modifiers::CONTROL,
@@ -187,6 +187,17 @@ fn parse_binding(binding: &QaHotkeyBinding) -> Result<HotKey, QaHotkeyError> {
187187
Ok(HotKey::new(Some(mods), code))
188188
}
189189

190+
fn normalize_modifier_tag(raw: &str) -> String {
191+
let tag = raw.trim().to_ascii_lowercase();
192+
#[cfg(target_os = "windows")]
193+
{
194+
if matches!(tag.as_str(), "cmd" | "command") {
195+
return "ctrl".to_string();
196+
}
197+
}
198+
tag
199+
}
200+
190201
/// 把用户配置的主键字符串解析成 keyboard_types::Code。
191202
/// 支持单字符(字母 / 数字 / 符号)+ 常见命名键(F1..F12 / Enter / Tab / Escape / Space)。
192203
fn parse_primary(raw: &str) -> Result<Code, QaHotkeyError> {
@@ -339,4 +350,24 @@ mod tests {
339350
Err(QaHotkeyError::UnsupportedKey(_))
340351
));
341352
}
353+
354+
#[test]
355+
fn cmd_modifier_normalizes_per_platform() {
356+
let binding = QaHotkeyBinding {
357+
primary: ";".into(),
358+
modifiers: vec!["cmd".into(), "shift".into()],
359+
};
360+
let parsed = parse_binding(&binding).expect("binding parses");
361+
362+
#[cfg(target_os = "windows")]
363+
{
364+
assert!(parsed.mods.contains(Modifiers::CONTROL));
365+
assert!(!parsed.mods.contains(Modifiers::SUPER));
366+
}
367+
368+
#[cfg(not(target_os = "windows"))]
369+
{
370+
assert!(parsed.mods.contains(Modifiers::SUPER));
371+
}
372+
}
342373
}

0 commit comments

Comments
 (0)