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:
张小白 authored and GitHub committed 2025-07-11 17:19:23 +08:00
1 parent 403f2fe3fa
commit c49166b65f
1 file changed
+8 -6
+8 -6
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
}