windows: Fix an issue where dead keys that require holding shift didn’t work properly (#34264)

Closes #34194

Release Notes:

- N/A
This commit is contained in:
张小白 2025-07-11 17:19:23 +08:00 committed by GitHub
parent 56d0ae6782
commit 8812e7cd14
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -130,11 +130,13 @@ pub(crate) fn generate_key_char(
let mut buffer = [0; 8];
let len = unsafe { ToUnicode(vkey.0 as u32, scan_code, Some(&state), &mut buffer, 1 << 2) };
if len > 0 {
let candidate = String::from_utf16_lossy(&buffer[..len as usize]);
if !candidate.is_empty() && !candidate.chars().next().unwrap().is_control() {
return Some(candidate);
}
match len {
len if len > 0 => String::from_utf16(&buffer[..len as usize])
.ok()
.filter(|candidate| {
!candidate.is_empty() && !candidate.chars().next().unwrap().is_control()
}),
len if len < 0 => String::from_utf16(&buffer[..(-len as usize)]).ok(),
_ => None,
}
None
}