mirror of
https://github.com/AutoMaker-Org/automaker.git
synced 2026-02-03 08:53:36 +00:00
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:
@@ -68,6 +68,12 @@ export function TerminalPanel({
|
|||||||
// Use refs for callbacks and values to avoid effect re-runs
|
// Use refs for callbacks and values to avoid effect re-runs
|
||||||
const onFocusRef = useRef(onFocus);
|
const onFocusRef = useRef(onFocus);
|
||||||
onFocusRef.current = 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);
|
const fontSizeRef = useRef(fontSize);
|
||||||
fontSizeRef.current = fontSize;
|
fontSizeRef.current = fontSize;
|
||||||
const themeRef = useRef(effectiveTheme);
|
const themeRef = useRef(effectiveTheme);
|
||||||
@@ -173,6 +179,37 @@ export function TerminalPanel({
|
|||||||
terminal.onData(() => {
|
terminal.onData(() => {
|
||||||
onFocusRef.current();
|
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();
|
initTerminal();
|
||||||
|
|||||||
Reference in New Issue
Block a user