Skip to content

fix: return focus to the terminal on palette close - #4

Merged
LukeGus merged 2 commits into
Termix-SSH:dev-1.1.2from
Kevsosmooth:fix/palette-focus-restore
Nov 8, 2026
Merged

LukeGus merged 2 commits into
Termix-SSH:dev-1.1.2from
Kevsosmooth:fix/palette-focus-restore

Conversation

@Kevsosmooth

Copy link
Copy Markdown

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

usePaletteDismiss records 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.

  • Commit 1 is a pure move: the Escape handler and handleAction move out of CommandPalette.tsx into src/frontend/shell/use-palette-dismiss.ts, with no behavior change.
  • Commit 2 adds the focus return in that hook.

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 the focus() call removed, the two focus-return tests fail. tsc -p . and Prettier pass.

@termix-triage-bot

Copy link
Copy Markdown

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 /termix review to run it again.

@LukeGus
LukeGus changed the base branch from main to dev-1.1.2 November 8, 2026 19:04
@LukeGus
LukeGus merged commit 1241610 into Termix-SSH:dev-1.1.2 Nov 8, 2026
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants