Files
winit/tests/macos_keyboard.rs
T
aiongg c8cd8aa149 W23: macOS: name keys pressed with ⌘ by the layout's ⌘ table
A key pressed with ⌘ was named by charactersIgnoringModifiers, which
ignores the layout's table for ⌘. On "Dvorak – QWERTY ⌘" the layout
types Dvorak letters but QWERTY ones with ⌘, so ⌘V was reported as ⌘K
and opened PdfCraft's command palette (storytold/pdfcraft#3655). With ⌘
held, the logical key is now UCKeyTranslate's character with cmdKey
(and shiftKey when Shift is held), falling back to the old rule when
the table has no character.

KeyEventExtMacOS::key_with_command reports the ⌘ table's character for
every key event, as key_without_modifiers does for the base table, so
shortcut matching and labels can use it without ⌘ held.
2026-10-21 18:07:40 +00:00

22 lines
901 B
Rust
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
//! Tests for the macOS key translation that run on every platform.
use std::path::Path;
// `command_key` is plain Rust.
#[allow(dead_code)]
#[path = "../src/platform_impl/macos/command_key.rs"]
mod command_key;
#[test]
fn macos_command_takes_the_layouts_command_table() {
// winit 0.30.13 names a key pressed with ⌘ by `charactersIgnoringModifiers`, which ignores the
// layout's ⌘ table: on "Dvorak – QWERTY ⌘", ⌘V was reported as ⌘K (storytold/pdfcraft#3655).
let path = Path::new(env!("CARGO_MANIFEST_DIR")).join("src/platform_impl/macos/event.rs");
let event = std::fs::read_to_string(path).unwrap();
assert!(
event.contains("match has_cmd.then(|| command_table(has_shift)).flatten() {"),
"a key pressed with ⌘ ignores the ⌘ table"
);
assert!(event.contains("uc_modifier_state(shift, true)"), "the ⌘ table isn't read with ⌘");
}