windows: Fix keystroke (#30753)

Closes #22656

Part of #29144, this PR completely rewrites the key handling logic on
Windows, making it much more consistent with how things work on macOS.
However, one remaining issue is that on Windows, we should be using
`Ctrl+Shift+4` instead of `Ctrl+$`. That part is expected to be
addressed in #29144.


Release Notes:

- N/A
This commit is contained in:
张小白 2025-05-15 20:49:06 +08:00 committed by GitHub
parent f021b401f4
commit 58ba833792
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
4 changed files with 287 additions and 280 deletions

View file

@ -56,6 +56,7 @@ impl Keystroke {
/// This method assumes that `self` was typed and `target' is in the keymap, and checks
/// both possibilities for self against the target.
pub(crate) fn should_match(&self, target: &Keystroke) -> bool {
#[cfg(not(target_os = "windows"))]
if let Some(key_char) = self
.key_char
.as_ref()
@ -72,6 +73,18 @@ impl Keystroke {
}
}
#[cfg(target_os = "windows")]
if let Some(key_char) = self
.key_char
.as_ref()
.filter(|key_char| key_char != &&self.key)
{
// On Windows, if key_char is set, then the typed keystroke produced the key_char
if &target.key == key_char && target.modifiers == Modifiers::none() {
return true;
}
}
target.modifiers == self.modifiers && target.key == self.key
}