Repository navigation
fix: return focus to the terminal on palette close - #4
Merged
LukeGus merged 2 commits intoNov 8, 2026
Merged
Conversation
|
AI review | Looks safe to merge The PR extracts the command palette's Escape key handler and action runner into a custom hook that restores focus to the previously focused element when the palette closes. The implementation is safe, follows React best practices, includes comprehensive tests, and adheres to all repository standards. No issues found. Reviewed fdf51ad. AI can be wrong, a maintainer still decides. Comment |
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.
Problem
Open the command palette from a terminal (double Shift or Ctrl+K), then close it with double Shift, Escape, or a click on the backdrop. Focus does not go back to the terminal: the palette's input is removed with the palette, focus falls to
document.body, and typing goes nowhere until you click the terminal again.Fix
usePaletteDismissrecords the focused element when the palette opens and focuses it again when the palette is dismissed, if it is still in the document and nothing else has taken focus. When an item is picked, focus is left to that action, since opening a tab or panel manages focus itself.handleActionmove out ofCommandPalette.tsxintosrc/frontend/shell/use-palette-dismiss.ts, with no behavior change.Tests
tests/frontend/shell/use-palette-dismiss.test.tsx: closes on Escape, returns focus on dismiss and on unmount, leaves focus alone after a picked action, and does not steal focus that moved elsewhere. With thefocus()call removed, the two focus-return tests fail.tsc -p .and Prettier pass.