Skip to content

fix: auto-focus terminal on new session creation#19

Merged
dakl merged 1 commit intomainfrom
switches-sessions
Mar 23, 2026
Merged

fix: auto-focus terminal on new session creation#19
dakl merged 1 commit intomainfrom
switches-sessions

Conversation

@dakl
Copy link
Copy Markdown
Owner

@dakl dakl commented Mar 23, 2026

Summary

Auto-focus the terminal when a new session is created and becomes the active session. This ensures keyboard input works immediately without requiring a manual click on the terminal area.

Problem

When a new session is created as the active session:

  1. The session state is set to active immediately
  2. TerminalView initializes the xterm instance in a requestAnimationFrame
  3. The focus effect fires on mount when isActive is already true, but terminalRef.current is still null
  4. The focus effect never re-fires because isActive never changes after mount

This caused users to need to click the terminal before they could input anything, including responding to Claude's folder trust prompts.

Solution

Add an explicit terminal.focus() call at the end of the initialization RAF when the session is already active. This handles the case where a terminal is created for an already-active session.

Testing

  • All existing tests pass (217/217)
  • Manual test: Create new session → terminal auto-focuses, keyboard input works immediately
  • Tested with Claude's folder trust prompt → no click needed to press Enter

What Changed

  • src/renderer/components/SessionView/TerminalView.tsx: Added focus call after terminal initialization when session is already active

When a new session is created as the active session, the terminal
initialization RAF fires before the focus effect can run, leaving
terminal.focus() unexecuted. Add explicit focus call after terminal
init when session is already active.

Fixes:
- Terminal not focused after new session creation (need to click to input)
- Keyboard input blocked until manual click on terminal area

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@dakl dakl merged commit bafda62 into main Mar 23, 2026
3 checks passed
@dakl dakl deleted the switches-sessions branch March 23, 2026 20:53
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.

1 participant