Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 32 additions & 1 deletion openless-all/app/src-tauri/src/qa_hotkey.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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();
Comment on lines +194 to +195
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Update Windows expectations for cmd alias behavior

On Windows targets this change remaps cmd/command to ctrl in parse_binding, but the existing parse_letter_binding unit test in the same file still asserts that cmd sets Modifiers::SUPER; that test will now fail whenever tests are run for target_os = "windows", creating a platform-specific red CI and hiding real regressions behind expected failures.

Useful? React with 👍 / 👎.

}
}
tag
}

/// 把用户配置的主键字符串解析成 keyboard_types::Code。
/// 支持单字符(字母 / 数字 / 符号)+ 常见命名键(F1..F12 / Enter / Tab / Escape / Space)。
fn parse_primary(raw: &str) -> Result<Code, QaHotkeyError> {
Expand Down Expand Up @@ -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));
}
}
}
Loading