From deae01712a034fb9a6caa4c1f13aa5f4b6243b7f Mon Sep 17 00:00:00 2001 From: SuperComboGamer Date: Sat, 13 Dec 2025 01:39:05 -0500 Subject: [PATCH] fix: intercept terminal shortcuts at xterm level MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit When the terminal is focused, xterm captures keyboard events before they reach the window. Use attachCustomKeyEventHandler to intercept Alt+D, Alt+Shift+D, and Alt+W directly at the xterm level. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.5 --- .../views/terminal-view/terminal-panel.tsx | 37 +++++++++++++++++++ 1 file changed, 37 insertions(+) diff --git a/apps/app/src/components/views/terminal-view/terminal-panel.tsx b/apps/app/src/components/views/terminal-view/terminal-panel.tsx index c0fb1eab..aef9bd19 100644 --- a/apps/app/src/components/views/terminal-view/terminal-panel.tsx +++ b/apps/app/src/components/views/terminal-view/terminal-panel.tsx @@ -68,6 +68,12 @@ export function TerminalPanel({ // Use refs for callbacks and values to avoid effect re-runs const onFocusRef = useRef(onFocus); onFocusRef.current = onFocus; + const onCloseRef = useRef(onClose); + onCloseRef.current = onClose; + const onSplitHorizontalRef = useRef(onSplitHorizontal); + onSplitHorizontalRef.current = onSplitHorizontal; + const onSplitVerticalRef = useRef(onSplitVertical); + onSplitVerticalRef.current = onSplitVertical; const fontSizeRef = useRef(fontSize); fontSizeRef.current = fontSize; const themeRef = useRef(effectiveTheme); @@ -173,6 +179,37 @@ export function TerminalPanel({ terminal.onData(() => { onFocusRef.current(); }); + + // Custom key handler to intercept terminal shortcuts + // Return false to prevent xterm from handling the key + terminal.attachCustomKeyEventHandler((event) => { + // Only intercept keydown events + if (event.type !== 'keydown') return true; + + // Alt+D - Split right + if (event.altKey && !event.shiftKey && !event.ctrlKey && !event.metaKey && event.key.toLowerCase() === 'd') { + event.preventDefault(); + onSplitHorizontalRef.current(); + return false; + } + + // Alt+Shift+D - Split down + if (event.altKey && event.shiftKey && !event.ctrlKey && !event.metaKey && event.key.toLowerCase() === 'd') { + event.preventDefault(); + onSplitVerticalRef.current(); + return false; + } + + // Alt+W - Close terminal + if (event.altKey && !event.shiftKey && !event.ctrlKey && !event.metaKey && event.key.toLowerCase() === 'w') { + event.preventDefault(); + onCloseRef.current(); + return false; + } + + // Let xterm handle all other keys + return true; + }); }; initTerminal();