Repository navigation
docs: Explain recovering focus when the focused element stops rendering - #3386
Merged
Merged
Conversation
When a view stops rendering the element that holds Focus (a table swapped for an empty state), the window keeps the old FocusId and key dispatch falls back to the dispatch tree's root node. The view's key_context bindings and on_action handlers then stop firing, and the Focus guide gave no hint why. Add a short section to the Focus guide, in English and Chinese, that explains the fallback and shows a root view restoring Focus with cx.on_focus_lost and window.focus_lost_restore_target, plus a symptom row in the "Verify and debug" table. Add the same pattern to the gpui-kit skill's focus-handle reference. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01PRpJSFk3zTwdgAJHehdZFm
Contributor
Author
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.
Description
The Focus guide does not say what happens when a view stops rendering the element that holds Focus, for example when a table is replaced by an empty state. In an app this shows up as "keyboard shortcuts stop working after a view is hidden".
What GPUI does (
gpui-pre0.3.8, the version pinned onmain):FocusId.Window::focus_node_id_in_rendered_frame(src/window.rs:6325) looks it up in the rendered dispatch tree and, when the element was not rendered, falls back todispatch_tree.root_node_id(). Key and action dispatch then walks the path to the root node only, so bindings under the view'skey_contextand itson_actionhandlers are skipped. Only handlers on the root node and globalcx.on_actionhandlers still run.focus_lost_listeners(src/window.rs:3406).Context::on_focus_lost(window, listener)(src/app/context.rs:616) registers one. While those listeners run,Window::focus_lost_restore_target(cx)(src/window.rs:2337) returns the closest ancestor of the lost element that is still rendered and focusable.The change:
website/docs/focus.md: a short section, "When the focused element stops rendering", that explains the fallback and shows a root view restoring Focus withon_focus_lostandfocus_lost_restore_target. A new row in the "Verify and debug" table for the symptom.website/zh-CN/docs/focus.md: the same section and table row in Chinese.skills/gpui-kit/references/gpui/focus-handle.md: the same pattern as item 4 under "Common Patterns". This file is source, not one of the vendored copies ofwebsite/docs/that AGENTS.md lists.This is a documentation-only change. It was written with AI assistance (Claude Code).
How to Test
website/docs/focus.mdandwebsite/zh-CN/docs/focus.md, and the new table row in each.crates/kitby path (sogpui-pre0.3.8), with aRenderimpl andmainaround it.cargo checkpassed with no errors and no warnings. The crate'ssrc/main.rs:src/main.rs
bun run test:docs) andtyposwere not run: neitherbunnortyposis installed on my machine. The change adds no links and no version strings.Checklist
PassedNot applicable: documentation only.cargo runfor story tests related to the changes.Tested macOS, Windows and Linux platforms performance (if the change is platform-specific)Not applicable: documentation only.🤖 Generated with Claude Code
https://claude.ai/code/session_01PRpJSFk3zTwdgAJHehdZFm