From 6de7229be53f74610a6440326129354888ac295e Mon Sep 17 00:00:00 2001 From: ssdfasd <2156608475@qq.com> Date: Fri, 20 Mar 2026 16:54:27 +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=A8=E9=BC=A0=E6=A0=87=E8=BF=BD=E8=B8=AA=E6=A8=A1?= =?UTF-8?q?=E5=BC=8F=E4=B8=8B=E7=9A=84=E6=BB=9A=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 | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/src/components/TerminalViewport.tsx b/src/components/TerminalViewport.tsx index 0157f3a..65eb121 100644 --- a/src/components/TerminalViewport.tsx +++ b/src/components/TerminalViewport.tsx @@ -112,6 +112,7 @@ 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); @@ -996,6 +997,26 @@ 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 }); + } + localTerminalTextarea = (terminal as unknown as { textarea?: HTMLTextAreaElement | null }).textarea ?? container.querySelector('textarea'); @@ -1082,6 +1103,8 @@ const TerminalViewport = React.forwardRef disposable.dispose()); restorePatchedScrollToBottom?.(); restorePatchedScrollToBottom = null; + mouseTrackingWheelCleanupRef.current?.(); + mouseTrackingWheelCleanupRef.current = null; if (localTerminalTextarea) { localTerminalTextarea.removeEventListener('focus', handleTerminalTextareaFocus); localTerminalTextarea.removeEventListener('blur', handleTerminalTextareaBlur);