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.

Fix Alt modifier stuck after Alt-Tab on Windows (#52220)

HuaGu-Dragon38270bc027a4
diff --git a/crates/gpui_windows/src/events.rs b/crates/gpui_windows/src/events.rs
index 21eb6bed899..23b0c078b8a 100644
--- a/crates/gpui_windows/src/events.rs
+++ b/crates/gpui_windows/src/events.rs
@@ -725,6 +725,25 @@ impl WindowsWindowInner {
fn handle_activate_msg(self: &Rc<Self>, wparam: WPARAM) -> Option<isize> {
let activated = wparam.loword() > 0;
let this = self.clone();
+
+ // When the window is activated (gains focus), reset the modifier tracking state.
+ // This fixes the issue where Alt-Tab away and back leaves stale modifier state
+ // (especially the Alt key) because Windows doesn't always send key-up events to
+ // windows that have lost focus.
+ if activated {
+ this.state.last_reported_modifiers.set(None);
+ this.state.last_reported_capslock.set(None);
+
+ if let Some(mut func) = this.state.callbacks.input.take() {
+ let input = PlatformInput::ModifiersChanged(ModifiersChangedEvent {
+ modifiers: current_modifiers(),
+ capslock: current_capslock(),
+ });
+ func(input);
+ this.state.callbacks.input.set(Some(func));
+ }
+ }
+
self.executor
.spawn(async move {
if let Some(mut func) = this.state.callbacks.active_status_change.take() {