Keep focus on the terminal after a channel switch (#35) #36

Merged
pedromcaraujo merged 1 commit from fix-palette-focus into main 2026-08-27 08:45:53 +01:00

Fixes #35.

Cause

Switching channels (palette or sidebar) left keyboard focus on <body>, so the next keystroke went nowhere until you clicked the terminal. focusTerm() retried only over [0,60,200,500] ms, but a channel switch rebuilds xterm's textarea and reconnects ttyd's websocket — often not ready inside 500 ms — so every retry no-oped. The immediate call from closePalette() also runs while the iframe is still navigating, seeing only the outgoing document.

Fix (web/index.html, focusTerm() only)

  • Widen the retry schedule to [0,60,150,300,500,800,1200,1800] ms so it outlasts a cold ttyd connect.
  • Add a focusGen token so the still-navigating closePalette() call is superseded by the new page's load-time call instead of fighting it.
  • Keep the stop-once-stuck behaviour (so a later click into the side panel isn't yanked back) and the touch no-op.

Verification

Needs a browser (can't verify from CI): Alt+K → pick another channel → type immediately without clicking; keystrokes should reach the shell. Test both a warm session and a cold one (slower ttyd connect), and confirm clicking into the issues drawer right after a switch still keeps focus where you clicked.

Fixes #35. ## Cause Switching channels (palette or sidebar) left keyboard focus on `<body>`, so the next keystroke went nowhere until you clicked the terminal. `focusTerm()` retried only over `[0,60,200,500]` ms, but a channel switch rebuilds xterm's textarea and reconnects ttyd's websocket — often not ready inside 500 ms — so every retry no-oped. The immediate call from `closePalette()` also runs while the iframe is still navigating, seeing only the outgoing document. ## Fix (`web/index.html`, `focusTerm()` only) - Widen the retry schedule to `[0,60,150,300,500,800,1200,1800]` ms so it outlasts a cold ttyd connect. - Add a `focusGen` token so the still-navigating `closePalette()` call is superseded by the new page's load-time call instead of fighting it. - Keep the stop-once-stuck behaviour (so a later click into the side panel isn't yanked back) and the touch no-op. ## Verification Needs a browser (can't verify from CI): Alt+K → pick another channel → type immediately without clicking; keystrokes should reach the shell. Test both a warm session and a cold one (slower ttyd connect), and confirm clicking into the issues drawer right after a switch still keeps focus where you clicked.
Keep focus on the terminal after a channel switch (#35)
All checks were successful
CI / check (pull_request) Successful in 7s
cdc84de9e4
Switching channels via the palette or sidebar left keyboard focus on <body>,
so the next keystroke went nowhere until you clicked the terminal.

focusTerm() retried only up to 500ms, but a channel switch rebuilds xterm's
textarea and reconnects ttyd's websocket, which often isn't ready that fast —
every retry no-oped and focus was lost. Widen the retry window to ~1.8s and
add a generation token so the call fired while the iframe is still navigating
(seeing only the outgoing document) is superseded by the new page's load-time
call instead of fighting it. Still stops once focus sticks, so a later click
into the side panel isn't yanked back; still a no-op on touch.

Closes #35.
Sign in to join this conversation.
No reviewers
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
pedromcaraujo/forge!36
No description provided.