X Tutup
Skip to content

fix(site): re-focus terminal on window focus for iframe embedding#22865

Open
lucasoeth wants to merge 1 commit intocoder:mainfrom
lucasoeth:lucasoeth/fix-terminal-focus-on-window-focus
Open

fix(site): re-focus terminal on window focus for iframe embedding#22865
lucasoeth wants to merge 1 commit intocoder:mainfrom
lucasoeth:lucasoeth/fix-terminal-focus-on-window-focus

Conversation

@lucasoeth
Copy link

Description

When the terminal page is embedded in an iframe (e.g. the Tasks view or third-party dashboards), switching between tabs causes the terminal to lose keyboard focus. The user has to click inside the terminal to start typing again.

The parent page can call iframe.contentWindow.focus() which fires the window focus event inside the iframe, but xterm.js does not listen for this event and does not re-focus its hidden textarea in response.

This adds a window focus event listener that calls terminal.focus(), so the terminal receives keyboard input immediately after a tab switch.

Impact

Changes

One useEffect added to TerminalPage.tsx (~10 lines).

Testing

  1. Open the Tasks view with multiple task tabs
  2. Click into the terminal and start typing
  3. Switch to a different task tab, then switch back
  4. Terminal should have focus — you can type immediately without clicking

When the terminal page is embedded in an iframe (e.g. the Tasks view or
third-party dashboards), switching between tabs causes the terminal to
lose keyboard focus. The parent page can call
`iframe.contentWindow.focus()` which fires the window "focus" event, but
xterm.js does not automatically re-focus its textarea in response.

Add a window "focus" event listener that calls `terminal.focus()`,
allowing the terminal to receive keyboard input immediately after a tab
switch without requiring an extra click.

Fixes coder#21149

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
@github-actions
Copy link

github-actions bot commented Mar 9, 2026


Thank you for your submission, we really appreciate it. Like many open-source projects, we ask that you sign our Contributor License Agreement before we can accept your contribution. You can sign the CLA by just posting a Pull Request Comment same as the below format.


I have read the CLA Document and I hereby sign the CLA


Lucas Soeth seems not to be a GitHub user. You need a GitHub account to be able to sign the CLA. If you have already a GitHub account, please add the email address used for this commit to your account.
You can retrigger this bot by commenting recheck in this Pull Request. Posted by the CLA Assistant Lite bot.

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.

Tasks: switching focus between tasks tabs in the sidebar sometimes loses focus on the coder_app on the right pane

2 participants

X Tutup