Skip to content

armgit / zed

Public Imported from GitHub
0

Code at the speed of thought – Zed is a high-performance, multiplayer code editor from the creators of Atom and Tree-sitter.

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

张小白8812e7cd1483
diff --git a/crates/gpui/src/platform/windows/keyboard.rs b/crates/gpui/src/platform/windows/keyboard.rs
index f5a148a97e9..371feb70c25 100644
--- a/crates/gpui/src/platform/windows/keyboard.rs
+++ b/crates/gpui/src/platform/windows/keyboard.rs
@@ -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
}