Restore mobile focus on tab return
This commit is contained in:
File diff suppressed because one or more lines are too long
@@ -602,16 +602,29 @@ class WebTerminal {
|
|||||||
// Connect WebSocket
|
// Connect WebSocket
|
||||||
this.connect();
|
this.connect();
|
||||||
|
|
||||||
|
const restoreFocus = () => {
|
||||||
|
if (isMobileDevice()) {
|
||||||
|
this.focusMobileInput();
|
||||||
|
} else {
|
||||||
|
this.terminal.focus();
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
// Focus terminal when returning to the tab
|
// Focus terminal when returning to the tab
|
||||||
document.addEventListener("visibilitychange", () => {
|
document.addEventListener("visibilitychange", () => {
|
||||||
if (!document.hidden) {
|
if (!document.hidden) {
|
||||||
this.terminal.focus();
|
restoreFocus();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
// Restore focus when browser window regains focus
|
// Restore focus when browser window regains focus
|
||||||
window.addEventListener("focus", () => {
|
window.addEventListener("focus", () => {
|
||||||
this.terminal.focus();
|
restoreFocus();
|
||||||
|
});
|
||||||
|
|
||||||
|
// Safari can restore tabs via bfcache without a focus event.
|
||||||
|
window.addEventListener("pageshow", () => {
|
||||||
|
restoreFocus();
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user