mirror of
https://github.com/storytold/winit.git
synced 2026-12-01 02:36:24 +01:00
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.
22 lines
901 B
Rust
22 lines
901 B
Rust
//! 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 ⌘");
|
||
}
|