fix: intercept terminal shortcuts at xterm level

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 <noreply@anthropic.com>
This commit is contained in:
SuperComboGamer
2025-12-13 01:39:05 -05:00
parent 14d1562903
commit deae01712a

View File

@@ -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();