Restore mobile focus on tab return

This commit is contained in:
GitHub Copilot
2026-01-30 00:56:40 +00:00
parent 8425662eca
commit ad4a05c13a
2 changed files with 23 additions and 10 deletions
File diff suppressed because one or more lines are too long
+15 -2
View File
@@ -602,16 +602,29 @@ class WebTerminal {
// Connect WebSocket
this.connect();
const restoreFocus = () => {
if (isMobileDevice()) {
this.focusMobileInput();
} else {
this.terminal.focus();
}
};
// Focus terminal when returning to the tab
document.addEventListener("visibilitychange", () => {
if (!document.hidden) {
this.terminal.focus();
restoreFocus();
}
});
// Restore focus when browser window regains focus
window.addEventListener("focus", () => {
this.terminal.focus();
restoreFocus();
});
// Safari can restore tabs via bfcache without a focus event.
window.addEventListener("pageshow", () => {
restoreFocus();
});
}