From 8812e7cd148301fe9ac37eeb98658d9bef6bced0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=BC=A0=E5=B0=8F=E7=99=BD?= <364772080@qq.com> Date: Fri, 11 Jul 2025 17:19:23 +0800 Subject: [PATCH] =?UTF-8?q?windows:=20Fix=20an=20issue=20where=20dead=20ke?= =?UTF-8?q?ys=20that=20require=20holding=20`shift`=20didn=E2=80=99t=20work?= =?UTF-8?q?=20properly=20(#34264)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Closes #34194 Release Notes: - N/A --- crates/gpui/src/platform/windows/keyboard.rs | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/crates/gpui/src/platform/windows/keyboard.rs b/crates/gpui/src/platform/windows/keyboard.rs index f5a148a97e..371feb70c2 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 }