Don't cancel renames or dismiss Go to Line when the window is deactivated (#61852) (cherry-pick to preview) - #61856
Merged
Conversation
…ated (#61852) Closes #39286 ## Problem Switching the keyboard layout on Wayland (e.g. GNOME's Super+Space) makes the compositor briefly grab the keyboard, which deactivates the Zed window. GPUI reports window deactivation as a blur of the focused element (`WindowFocusEvent` is emitted with an empty `current_focus_path`), so controls that dismiss or cancel on blur treated it as the user abandoning them. The same happens when switching to another app window. As discussed in #39286 with @MrSubidubi, the desired behavior is to keep these controls open and focused across window deactivation. ## Fix Guard the blur-driven cancel/dismiss handlers with `window.is_window_active()`, following the pattern established for pickers in #41320: - Project panel: in-progress rename / new file / new directory inputs are no longer cancelled when the window is deactivated - Collab panel: in-progress channel rename is no longer cancelled - Go to Line: the dialog is no longer dismissed In-window focus changes (clicking elsewhere, Escape) keep the existing commit/cancel semantics. The terminal tab rename needed no change: it re-checks `FocusHandle::is_focused`, which reads `window.focus` and that survives deactivation. Command palette, file finder, and outline were already fixed by #41320. Added a regression test (`test_rename_survives_window_deactivation`) that starts a rename, deactivates the window via the test platform, and asserts the edit state survives. Two milder siblings were left unchanged to keep this PR focused, flagging them for a maintainer decision: the notebook markdown cell exits edit mode on blur (`crates/repl/src/notebook/cell.rs`), and the diagnostics view prunes diagnosticless buffers on blur (`crates/diagnostics/src/diagnostics.rs`). Longer term it may be worth carrying the blur cause in the event itself (e.g. a `FocusMoved` vs `WindowDeactivated` reason on `FocusOutEvent` and `EditorEvent::Blurred`), so each handler has to state which causes it handles instead of relying on an opt-in guard; happy to file a separate issue for that. ## Before https://github.com/user-attachments/assets/9eec1bb5-1881-4b3a-80ef-a287e23219ca ## After https://github.com/user-attachments/assets/49b8775c-175a-4882-835d-871432c0b315 ## Suggested .rules additions > Handlers that cancel or dismiss UI on blur (`EditorEvent::Blurred`, `on_blur`, `on_focus_out`) must check `window.is_window_active()` first: GPUI reports window deactivation (app switch, layout switcher grabbing the keyboard) as a blur of the focused element, and dismissing there loses user input. Release Notes: - Fixed in-progress file renames, channel renames, and the Go to Line dialog being cancelled when the window is deactivated, e.g. by a keyboard layout switch on Wayland or by switching to another application ([#39286](#39286)). --------- Co-authored-by: MrSubidubi <finn@zed.dev>
jolutz
pushed a commit
to jolutz/zed
that referenced
this pull request
Aug 8, 2026
…ated (zed-industries#61852) (cherry-pick to preview) (zed-industries#61856) Cherry-pick of zed-industries#61852 to preview ---- Closes zed-industries#39286 ## Problem Switching the keyboard layout on Wayland (e.g. GNOME's Super+Space) makes the compositor briefly grab the keyboard, which deactivates the Zed window. GPUI reports window deactivation as a blur of the focused element (`WindowFocusEvent` is emitted with an empty `current_focus_path`), so controls that dismiss or cancel on blur treated it as the user abandoning them. The same happens when switching to another app window. As discussed in zed-industries#39286 with @MrSubidubi, the desired behavior is to keep these controls open and focused across window deactivation. ## Fix Guard the blur-driven cancel/dismiss handlers with `window.is_window_active()`, following the pattern established for pickers in zed-industries#41320: - Project panel: in-progress rename / new file / new directory inputs are no longer cancelled when the window is deactivated - Collab panel: in-progress channel rename is no longer cancelled - Go to Line: the dialog is no longer dismissed In-window focus changes (clicking elsewhere, Escape) keep the existing commit/cancel semantics. The terminal tab rename needed no change: it re-checks `FocusHandle::is_focused`, which reads `window.focus` and that survives deactivation. Command palette, file finder, and outline were already fixed by zed-industries#41320. Added a regression test (`test_rename_survives_window_deactivation`) that starts a rename, deactivates the window via the test platform, and asserts the edit state survives. Two milder siblings were left unchanged to keep this PR focused, flagging them for a maintainer decision: the notebook markdown cell exits edit mode on blur (`crates/repl/src/notebook/cell.rs`), and the diagnostics view prunes diagnosticless buffers on blur (`crates/diagnostics/src/diagnostics.rs`). Longer term it may be worth carrying the blur cause in the event itself (e.g. a `FocusMoved` vs `WindowDeactivated` reason on `FocusOutEvent` and `EditorEvent::Blurred`), so each handler has to state which causes it handles instead of relying on an opt-in guard; happy to file a separate issue for that. ## Before https://github.com/user-attachments/assets/9eec1bb5-1881-4b3a-80ef-a287e23219ca ## After https://github.com/user-attachments/assets/49b8775c-175a-4882-835d-871432c0b315 ## Suggested .rules additions > Handlers that cancel or dismiss UI on blur (`EditorEvent::Blurred`, `on_blur`, `on_focus_out`) must check `window.is_window_active()` first: GPUI reports window deactivation (app switch, layout switcher grabbing the keyboard) as a blur of the focused element, and dismissing there loses user input. Release Notes: - Fixed in-progress file renames, channel renames, and the Go to Line dialog being cancelled when the window is deactivated, e.g. by a keyboard layout switch on Wayland or by switching to another application ([zed-industries#39286](zed-industries#39286)). --------- Co-authored-by: MrSubidubi <finn@zed.dev> Co-authored-by: Mikhail Butvin <butvin.mikhail@gmail.com> Co-authored-by: MrSubidubi <finn@zed.dev>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Cherry-pick of #61852 to preview
Closes #39286
Problem
Switching the keyboard layout on Wayland (e.g. GNOME's Super+Space)
makes the compositor briefly grab the keyboard, which deactivates the
Zed window. GPUI reports window deactivation as a blur of the focused
element (
WindowFocusEventis emitted with an emptycurrent_focus_path), so controls that dismiss or cancel on blurtreated it as the user abandoning them. The same happens when switching
to another app window. As discussed in #39286 with @MrSubidubi, the
desired behavior is to keep these controls open and focused across
window deactivation.
Fix
Guard the blur-driven cancel/dismiss handlers with
window.is_window_active(), following the pattern established forpickers in #41320:
are no longer cancelled when the window is deactivated
In-window focus changes (clicking elsewhere, Escape) keep the existing
commit/cancel semantics. The terminal tab rename needed no change: it
re-checks
FocusHandle::is_focused, which readswindow.focusand thatsurvives deactivation. Command palette, file finder, and outline were
already fixed by #41320.
Added a regression test (
test_rename_survives_window_deactivation)that starts a rename, deactivates the window via the test platform, and
asserts the edit state survives.
Two milder siblings were left unchanged to keep this PR focused,
flagging them for a maintainer decision: the notebook markdown cell
exits edit mode on blur (
crates/repl/src/notebook/cell.rs), and thediagnostics view prunes diagnosticless buffers on blur
(
crates/diagnostics/src/diagnostics.rs).Longer term it may be worth carrying the blur cause in the event itself
(e.g. a
FocusMovedvsWindowDeactivatedreason onFocusOutEventand
EditorEvent::Blurred), so each handler has to state which causesit handles instead of relying on an opt-in guard; happy to file a
separate issue for that.
Before
before.mp4
After
after.mp4
Suggested .rules additions
Release Notes:
dialog being cancelled when the window is deactivated, e.g. by a
keyboard layout switch on Wayland or by switching to another application
(#39286).
Co-authored-by: MrSubidubi finn@zed.dev