Problem
When clicking a session in the left sidebar, keyboard focus stays on the WPF sidebar item that was clicked — it does not "jump into" the selected CLI. The user has to click into the terminal area before they can start typing.
The root cause is in TerminalBridge.FocusTerminal(): it only posts a JS focus message to xterm.js inside the WebView2. That focuses the inner xterm textarea at the DOM level but does nothing at the WPF level, so the WebView2 host never actually gains keyboard focus when another WPF control (the clicked sidebar Border) currently holds it.
The same flow runs from Ctrl+Tab cycling and from the OnWindowActivated Alt+Tab refocus — the latter happens to work because focus was already on the WebView2 before the window deactivated, but a fresh sidebar click breaks the assumption.
Solution
- Make
TerminalBridge.FocusTerminal() call _webView.Focus() in addition to posting the JS focus message, so WPF keyboard focus actually moves onto the WebView2 host.
- Add a new
AppSettings.AutoFocusTerminalOnSelect setting (default true) that gates the focus call inside MainViewModel.FocusSession.
- Surface the setting in the Settings window under "SESSION SETTINGS" as "Auto-focus terminal when selecting a session".
This means:
- Default behaviour: clicking a sidebar session (or
Ctrl+Tab cycling) immediately moves focus into that session's terminal — no extra click needed.
- Users who prefer the old behaviour can disable the setting; selection still updates
ActiveSession and the active-terminal highlight, but focus is left where it was.
Files affected
src/CodeShellManager/Models/AppState.cs — new AutoFocusTerminalOnSelect property on AppSettings.
src/CodeShellManager/Terminal/TerminalBridge.cs — FocusTerminal() now also calls _webView.Focus().
src/CodeShellManager/ViewModels/MainViewModel.cs — FocusSession gates the focus call on the setting.
src/CodeShellManager/Views/SettingsWindow.xaml + .xaml.cs — new checkbox with clone/populate/save wiring.
src/CodeShellManager/MainWindow.xaml.cs — copy edited value back into _vm.Settings.
Problem
When clicking a session in the left sidebar, keyboard focus stays on the WPF sidebar item that was clicked — it does not "jump into" the selected CLI. The user has to click into the terminal area before they can start typing.
The root cause is in
TerminalBridge.FocusTerminal(): it only posts a JSfocusmessage to xterm.js inside the WebView2. That focuses the inner xterm textarea at the DOM level but does nothing at the WPF level, so the WebView2 host never actually gains keyboard focus when another WPF control (the clicked sidebar Border) currently holds it.The same flow runs from
Ctrl+Tabcycling and from theOnWindowActivatedAlt+Tab refocus — the latter happens to work because focus was already on the WebView2 before the window deactivated, but a fresh sidebar click breaks the assumption.Solution
TerminalBridge.FocusTerminal()call_webView.Focus()in addition to posting the JS focus message, so WPF keyboard focus actually moves onto the WebView2 host.AppSettings.AutoFocusTerminalOnSelectsetting (defaulttrue) that gates the focus call insideMainViewModel.FocusSession.This means:
Ctrl+Tabcycling) immediately moves focus into that session's terminal — no extra click needed.ActiveSessionand the active-terminal highlight, but focus is left where it was.Files affected
src/CodeShellManager/Models/AppState.cs— newAutoFocusTerminalOnSelectproperty onAppSettings.src/CodeShellManager/Terminal/TerminalBridge.cs—FocusTerminal()now also calls_webView.Focus().src/CodeShellManager/ViewModels/MainViewModel.cs—FocusSessiongates the focus call on the setting.src/CodeShellManager/Views/SettingsWindow.xaml+.xaml.cs— new checkbox with clone/populate/save wiring.src/CodeShellManager/MainWindow.xaml.cs— copy edited value back into_vm.Settings.