From 77d158909398b6d4ff83f5dabaaeaca0484d7d75 Mon Sep 17 00:00:00 2001 From: ssdfasd <2156608475@qq.com> Date: Fri, 20 Mar 2026 17:06:37 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E6=94=AF=E6=8C=81=E7=BB=88=E7=AB=AFGUI?= =?UTF-8?q?=E5=BA=94=E7=94=A8alternate=20screen=E6=A8=A1=E5=BC=8F=E6=BB=9A?= =?UTF-8?q?=E8=BD=AE=E4=BA=8B=E4=BB=B6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/components/TerminalViewport.tsx | 35 +++++++++++++---------------- 1 file changed, 16 insertions(+), 19 deletions(-) diff --git a/src/components/TerminalViewport.tsx b/src/components/TerminalViewport.tsx index 65eb121..10adf6d 100644 --- a/src/components/TerminalViewport.tsx +++ b/src/components/TerminalViewport.tsx @@ -112,7 +112,6 @@ const TerminalViewport = React.forwardRef(null); const followOutputRef = React.useRef(true); const touchScrollCleanupRef = React.useRef<(() => void) | null>(null); - const mouseTrackingWheelCleanupRef = React.useRef<(() => void) | null>(null); const viewportDiscoveryTimeoutRef = React.useRef(null); const viewportDiscoveryAttemptsRef = React.useRef(0); const hiddenInputRef = React.useRef(null); @@ -999,22 +998,22 @@ const TerminalViewport = React.forwardRef { - canvas.removeEventListener('wheel', handleMouseTrackingWheel, { capture: true }); - }; - const handleMouseTrackingWheel = (event: WheelEvent) => { - const wasmTerm = terminal.wasmTerm; - if (wasmTerm && wasmTerm.hasMouseTracking()) { - event.stopImmediatePropagation(); - const rect = canvas.getBoundingClientRect(); - const x = Math.round((event.clientX - rect.left) / (rect.width / terminal.cols)); - const y = Math.round((event.clientY - rect.top) / (rect.height / terminal.rows)); - const button = event.deltaY < 0 ? 64 : 65; - terminal.input(`\x1b[<${button};${x};${y}M`); - terminal.input(`\x1b[<${button - 32};${x};${y}m`); - } - }; - canvas.addEventListener('wheel', handleMouseTrackingWheel, { capture: true }); + (terminal as unknown as { attachCustomWheelEventHandler?: (handler: (event: WheelEvent) => boolean) => void }) + .attachCustomWheelEventHandler?.((event: WheelEvent) => { + const wasmTerm = terminal.wasmTerm; + if (!wasmTerm) return false; + + if (wasmTerm.isAlternateScreen() || wasmTerm.hasMouseTracking()) { + const rect = canvas.getBoundingClientRect(); + const x = Math.round((event.clientX - rect.left) / (rect.width / terminal.cols)); + const y = Math.round((event.clientY - rect.top) / (rect.height / terminal.rows)); + const button = event.deltaY < 0 ? 64 : 65; + terminal.input(`\x1b[<${button};${x};${y}M`); + terminal.input(`\x1b[<${button - 32};${x};${y}m`); + return true; + } + return false; + }); } localTerminalTextarea = @@ -1103,8 +1102,6 @@ const TerminalViewport = React.forwardRef disposable.dispose()); restorePatchedScrollToBottom?.(); restorePatchedScrollToBottom = null; - mouseTrackingWheelCleanupRef.current?.(); - mouseTrackingWheelCleanupRef.current = null; if (localTerminalTextarea) { localTerminalTextarea.removeEventListener('focus', handleTerminalTextareaFocus); localTerminalTextarea.removeEventListener('blur', handleTerminalTextareaBlur);