Skip to content

feat: auto-focus terminal when selecting a session#14

Merged
AThraen merged 2 commits into
mainfrom
feat/auto-focus-terminal-on-select
May 10, 2026
Merged

feat: auto-focus terminal when selecting a session#14
AThraen merged 2 commits into
mainfrom
feat/auto-focus-terminal-on-select

Conversation

@mortenaslo
Copy link
Copy Markdown
Contributor

Closes #13.

Summary

  • Sidebar click (and Ctrl+Tab cycling) now moves keyboard focus into the selected session's terminal so the user can start typing immediately.
  • TerminalBridge.FocusTerminal() now calls _webView.Focus() in addition to posting the JS focus message — without this, WPF keyboard focus stays on the clicked sidebar Border and the JS term.focus() has no effect at the WPF level.
  • New AppSettings.AutoFocusTerminalOnSelect (default true) gates the focus call inside MainViewModel.FocusSession, surfaced as a checkbox in the Settings window under SESSION SETTINGS. When disabled, ActiveSession and the active-terminal highlight still update; only the focus jump is skipped.

Test plan

  • Click a session in the sidebar → caret blinks in that session's terminal, typing reaches the CLI without an extra click.
  • Ctrl+Tab and Ctrl+Shift+Tab cycle sessions and focus follows.
  • Toggle "Auto-focus terminal when selecting a session" off in Settings → clicking another session changes the active-terminal highlight but keyboard focus stays where it was.
  • Re-enable the setting → behaviour returns to focus-on-select.
  • Setting persists across app restart (state.json).
  • Alt+Tab back into the app still refocuses the active terminal (regression check on OnWindowActivated).

Clicking a sidebar session now moves keyboard focus into that session's
terminal so the user can start typing immediately — previously focus
stayed on the WPF sidebar Border and keystrokes went nowhere until the
user clicked the terminal pane.

- TerminalBridge.FocusTerminal now calls _webView.Focus() in addition
  to posting the JS focus message, so WPF keyboard focus actually
  moves onto the WebView2 host (the JS term.focus() alone does not
  do this when another WPF control holds focus).
- New AppSettings.AutoFocusTerminalOnSelect (default true) gates the
  focus call inside MainViewModel.FocusSession, so users who prefer
  the previous behaviour can opt out. ActiveSession and the
  active-terminal highlight still update either way.
- Settings window exposes the toggle under SESSION SETTINGS as
  "Auto-focus terminal when selecting a session".

Closes #13
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR improves session switching UX by automatically moving keyboard focus into the selected session’s terminal (WebView2) so users can type immediately, with a new setting to disable focus-on-select.

Changes:

  • Update TerminalBridge.FocusTerminal() to focus the WebView2 host control before sending the JS focus message.
  • Add AppSettings.AutoFocusTerminalOnSelect (default true) and gate focus-on-select in MainViewModel.FocusSession.
  • Surface the new setting in the Settings window and persist it via existing state saving.

Reviewed changes

Copilot reviewed 6 out of 6 changed files in this pull request and generated 1 comment.

Show a summary per file
File Description
src/CodeShellManager/Terminal/TerminalBridge.cs Ensures WPF focus moves onto WebView2 before JS focus message is posted.
src/CodeShellManager/ViewModels/MainViewModel.cs Gates focus-on-select behavior behind a new settings flag.
src/CodeShellManager/Models/AppState.cs Adds a persisted AutoFocusTerminalOnSelect setting (default enabled).
src/CodeShellManager/Views/SettingsWindow.xaml Adds a checkbox UI to toggle auto-focus-on-select.
src/CodeShellManager/Views/SettingsWindow.xaml.cs Wires checkbox to edited settings clone/load/save.
src/CodeShellManager/MainWindow.xaml.cs Copies edited setting back into the live view model settings before saving state.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines 23 to +27
_edited = new AppSettings
{
AutoRestoreSessions = current.AutoRestoreSessions,
AutoResumeClaude = current.AutoResumeClaude,
AutoFocusTerminalOnSelect = current.AutoFocusTerminalOnSelect,
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@copilot apply changes based on this feedback

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Applied in 10c6b07: SettingsWindow now deep-copies current.LaunchCommands into _edited (LaunchCommands = current.LaunchCommands.ToList()), so opening/saving Settings no longer resets customized launch commands to defaults.

Copilot AI requested a review from AThraen May 10, 2026 14:13
@AThraen AThraen merged commit a9f3b6e into main May 10, 2026
1 check passed
@AThraen AThraen deleted the feat/auto-focus-terminal-on-select branch May 10, 2026 14:16
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.

Auto-focus terminal when selecting a session

4 participants