diff --git a/App.tsx b/App.tsx index 0095872e2..664022760 100755 --- a/App.tsx +++ b/App.tsx @@ -7,6 +7,7 @@ import { useVaultState } from './application/state/useVaultState'; import { useWindowControls } from './application/state/useWindowControls'; import { I18nProvider, useI18n } from './application/i18n/I18nProvider'; import { matchesKeyBinding } from './domain/models'; +import { getAppLevelActions } from './application/state/useGlobalHotkeys'; import { resolveHostAuth } from './domain/sshAuth'; import { netcattyBridge } from './infrastructure/services/netcattyBridge'; import { TopTabs } from './components/TopTabs'; @@ -438,13 +439,30 @@ function App({ settings }: { settings: SettingsState }) { // Note: xterm terminal handles its own key interception via attachCustomKeyEventHandler const target = e.target as HTMLElement; const isFormElement = target.tagName === 'INPUT' || target.tagName === 'TEXTAREA' || target.isContentEditable; + const isXtermInput = + target instanceof HTMLElement && + !!target.closest?.(".xterm, .xterm-helper-textarea, .xterm-screen, .xterm-viewport"); - if (isFormElement && e.key !== 'Escape') { + if (isFormElement && !isXtermInput && e.key !== 'Escape') { return; } const isTerminalElement = - target instanceof HTMLElement && !!target.closest?.(".xterm"); + target instanceof HTMLElement && + !!target.closest?.(".xterm, .xterm-helper-textarea, .xterm-screen, .xterm-viewport"); + const isTerminalInPath = Boolean( + e.composedPath?.().some( + (node) => + node instanceof HTMLElement && + (node.classList.contains("xterm") || + node.classList.contains("xterm-helper-textarea") || + node.classList.contains("xterm-screen") || + node.classList.contains("xterm-viewport") || + node.hasAttribute("data-session-id")), + ), + ); + + const appLevelActions = getAppLevelActions(); // Check each key binding for (const binding of keyBindings) { @@ -463,6 +481,19 @@ function App({ settings }: { settings: SettingsState }) { e.preventDefault(); e.stopPropagation(); + if (IS_DEV) { + console.log('[Hotkeys] Global handle', { + action: binding.action, + key: e.key, + meta: e.metaKey, + ctrl: e.ctrlKey, + alt: e.altKey, + shift: e.shiftKey, + targetTag: target?.tagName, + isTerminalElement, + isTerminalInPath, + }); + } executeHotkeyAction(binding.action, e); return; } diff --git a/components/terminal/runtime/createXTermRuntime.ts b/components/terminal/runtime/createXTermRuntime.ts index c8a13620c..ca003932e 100644 --- a/components/terminal/runtime/createXTermRuntime.ts +++ b/components/terminal/runtime/createXTermRuntime.ts @@ -296,6 +296,9 @@ export const createXTermRuntime = (ctx: CreateXTermRuntimeContext): XTermRuntime const terminalActions = getTerminalPassthroughActions(); term.attachCustomKeyEventHandler((e: KeyboardEvent) => { + if (e.type !== "keydown") { + return true; + } if ((e.ctrlKey || e.metaKey) && e.key === "f" && e.type === "keydown") { e.preventDefault(); ctx.setIsSearchOpen(true); @@ -317,13 +320,22 @@ export const createXTermRuntime = (ctx: CreateXTermRuntimeContext): XTermRuntime const { action } = matched; if (appLevelActions.has(action)) { - e.preventDefault(); - hotkeyCallback?.(action, e); - return false; + return true; // Let app-level handler process it } if (terminalActions.has(action)) { e.preventDefault(); + e.stopPropagation(); + if (import.meta.env.DEV) { + console.log('[Hotkeys] Xterm terminal-level', { + action, + key: e.key, + meta: e.metaKey, + ctrl: e.ctrlKey, + alt: e.altKey, + shift: e.shiftKey, + }); + } switch (action) { case "copy": { const selection = term.getSelection();