From 3dc41440070370a170b20a7ffbe2630b86c5e27e Mon Sep 17 00:00:00 2001 From: "douboer@gmail.com" Date: Tue, 3 Mar 2026 17:05:40 +0800 Subject: [PATCH] update at 2026-03-03 17:05:40 --- wetty/src/assets/scss/terminal.scss | 1 + wetty/src/client/wetty/mobile.ts | 54 +++++++++++------------------ 2 files changed, 22 insertions(+), 33 deletions(-) diff --git a/wetty/src/assets/scss/terminal.scss b/wetty/src/assets/scss/terminal.scss index c447840..b83c5d9 100644 --- a/wetty/src/assets/scss/terminal.scss +++ b/wetty/src/assets/scss/terminal.scss @@ -1,4 +1,5 @@ #terminal { + box-sizing: border-box; display: flex; height: 100%; position: relative; diff --git a/wetty/src/client/wetty/mobile.ts b/wetty/src/client/wetty/mobile.ts index 2fd9e5f..6147bd0 100644 --- a/wetty/src/client/wetty/mobile.ts +++ b/wetty/src/client/wetty/mobile.ts @@ -11,45 +11,33 @@ export function mobileKeyboard(): void { } export function initMobileViewport(term: any): void { - // Safari/iOS 上阻止页面随着键盘弹出连带回弹上卷 - document.body.style.position = 'fixed'; - document.body.style.width = '100%'; - document.body.style.height = '100%'; - document.body.style.overflow = 'hidden'; - - // 劫持容器,阻止橡皮筋翻页穿透 - document.addEventListener('touchmove', (e) => { - if (!(e.target as Element).closest('.xterm-viewport')) { - e.preventDefault(); - } - }, { passive: false }); - if (window.visualViewport) { const handleResize = () => { - // 计算键盘弹起遮挡区域(针对不同平台浏览器处理) - let bottomInset = 0; - if (window.visualViewport) { - bottomInset = Math.max( - 0, - window.innerHeight - (window.visualViewport.height + window.visualViewport.offsetTop) - ); - } - - const termWrapper = document.getElementById('terminal'); // 或获取最近的包装器 - if (termWrapper) { - if (bottomInset > 0) { - termWrapper.style.paddingBottom = `${bottomInset}px`; - } else { - termWrapper.style.paddingBottom = '0px'; - } - } - - // 调整完包裹层高度后,通知 xterm 重新按新的可用高度进行行列计算 + // 类似 xterminal,给软键盘和页面重排一点时间 setTimeout(() => { + let bottomInset = 0; + if (window.visualViewport) { + bottomInset = Math.max( + 0, + window.innerHeight - (window.visualViewport.height + window.visualViewport.offsetTop) + ); + } + + const termWrapper = document.getElementById('terminal'); // 外层容器 + if (termWrapper) { + if (bottomInset > 0) { + termWrapper.style.paddingBottom = `${bottomInset}px`; + } else { + termWrapper.style.paddingBottom = '0px'; + } + } + + // 通知 xterm 重新按新的可用高度进行行列计算,类似于 xterminal 重新适配行 if (term && term.fitAddon) { term.fitAddon.fit(); + term.scrollToBottom(); } - }, 50); + }, 100); }; window.visualViewport.addEventListener('resize', handleResize);