From cf86c166cfcc09f5c25b6f477bbd223c3bb46eeb Mon Sep 17 00:00:00 2001 From: bincxz <16399091+binaricat@users.noreply.github.com> Date: Tue, 10 Mar 2026 00:59:44 +0800 Subject: [PATCH] fix: Prevent xterm.js right-click behavior from interfering with tmux/vim popups when mouse tracking is active. --- components/Terminal.tsx | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) diff --git a/components/Terminal.tsx b/components/Terminal.tsx index 71475ee5b..08f287558 100644 --- a/components/Terminal.tsx +++ b/components/Terminal.tsx @@ -908,6 +908,37 @@ const TerminalComponent: React.FC = ({ return () => disposable.dispose(); }, [sessionId]); + // Prevent xterm.js's built-in rightClickHandler and right-button mouseup + // from interfering with tmux/vim popup menus when mouse tracking is active. + // - contextmenu: xterm.js calls textarea.select() which steals focus + // - mouseup (button 2): tmux interprets the right-button release as a + // dismiss action, closing the popup menu immediately after it appears + // Both are intercepted at the capture phase before xterm.js's own listeners. + useEffect(() => { + const el = containerRef.current; + if (!el) return; + + const handleContextMenuCapture = (e: MouseEvent) => { + if (mouseTrackingRef.current) { + e.preventDefault(); + e.stopImmediatePropagation(); + } + }; + + const handleMouseUpCapture = (e: MouseEvent) => { + if (e.button === 2 && mouseTrackingRef.current) { + e.stopImmediatePropagation(); + } + }; + + el.addEventListener('contextmenu', handleContextMenuCapture, true); + el.addEventListener('mouseup', handleMouseUpCapture, true); + return () => { + el.removeEventListener('contextmenu', handleContextMenuCapture, true); + el.removeEventListener('mouseup', handleMouseUpCapture, true); + }; + }, [sessionId]); + useEffect(() => { let resizeTimeout: ReturnType | null = null;