Palette/sidebar channel switch doesn't focus the terminal (must click to type) #35
Labels
No labels
bug
docs
enhancement
good first issue
No milestone
No project
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set.
Reference
pedromcaraujo/forge#35
Loading…
Add table
Add a link
Reference in a new issue
No description provided.
Delete branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Symptom
Switching channels via the command palette (Alt+K → Enter, or clicking an entry) leaves keyboard focus off the terminal — the next keystroke goes nowhere and you have to click the terminal before you can type. Switching by clicking the sidebar has the same underlying path.
Diagnosis
It is not a missing focus call —
focusTerm()is invoked twice on a palette switch:closePalette()calls it immediately (web/index.html).loadhandler calls it when the new channel's document loads.The problem is timing.
activate()runsgo(name), which setsframe.srcand reloads the iframe.focusTerm()retries only at[0, 60, 200, 500]ms, then gives up (donenever becomes true becauseframe.contentDocument.activeElement === tais never satisfied). On a channel switch the new xterm textarea — and the ttyd websocket it needs — frequently isn't ready inside that 500 ms window, so every retry no-ops and focus is left on<body>. The immediateclosePalette()call can also "succeed" against the outgoing document (settingdone=true) a beat before navigation replaces it, so focus is then lost with no further retries.Fix ideas
focusTerm()'s retry schedule past ttyd's connect (e.g. add ~900/1500 ms attempts), and don't let a focus that sticks on the old document before navigation count as done.load(already wired) and make its retry window long enough for ttyd.Desktop only —
focusTerm()is intentionally a no-op on touch (focusing the textarea pops the Android soft keyboard).Verification
Needs a browser: Alt+K → pick another channel → type immediately without clicking; the keystrokes should reach the shell. Check both an already-connected session and a cold one (slower ttyd connect).