diff --git a/frontend/app/store/keymodel.ts b/frontend/app/store/keymodel.ts index 0aafbe174..a46846861 100644 --- a/frontend/app/store/keymodel.ts +++ b/frontend/app/store/keymodel.ts @@ -282,6 +282,11 @@ function registerGlobalKeys() { getApi().registerGlobalWebviewKeys(allKeys); } +function getAllGlobalKeyBindings(): string[] { + const allKeys = Array.from(globalKeyMap.keys()); + return allKeys; +} + // these keyboard events happen *anywhere*, even if you have focus in an input or somewhere else. function handleGlobalWaveKeyboardEvents(waveEvent: WaveKeyboardEvent): boolean { for (const key of globalKeyMap.keys()) { @@ -297,6 +302,7 @@ function handleGlobalWaveKeyboardEvents(waveEvent: WaveKeyboardEvent): boolean { export { appHandleKeyDown, + getAllGlobalKeyBindings, getSimpleControlShiftAtom, registerControlShiftStateUpdateHandler, registerElectronReinjectKeyHandler, diff --git a/frontend/app/view/term/term.tsx b/frontend/app/view/term/term.tsx index 3484d6126..5a4ff85b6 100644 --- a/frontend/app/view/term/term.tsx +++ b/frontend/app/view/term/term.tsx @@ -1,11 +1,12 @@ // Copyright 2024, Command Line Inc. // SPDX-License-Identifier: Apache-2.0 +import { getAllGlobalKeyBindings } from "@/app/store/keymodel"; import { waveEventSubscribe } from "@/app/store/wps"; import { RpcApi } from "@/app/store/wshclientapi"; import { WindowRpcClient } from "@/app/store/wshrpcutil"; import { VDomView } from "@/app/view/term/vdom"; -import { PLATFORM, WOS, atoms, getConnStatusAtom, globalStore, useSettingsPrefixAtom } from "@/store/global"; +import { WOS, atoms, getConnStatusAtom, globalStore, useSettingsPrefixAtom } from "@/store/global"; import * as services from "@/store/services"; import * as keyutil from "@/util/keyutil"; import * as util from "@/util/util"; @@ -265,6 +266,7 @@ const TerminalView = ({ blockId, model }: TerminalViewProps) => { if (waveEvent.type != "keydown") { return true; } + // deal with terminal specific keybindings if (keyutil.checkKeyPressed(waveEvent, "Cmd:Escape")) { event.preventDefault(); event.stopPropagation(); @@ -274,37 +276,20 @@ const TerminalView = ({ blockId, model }: TerminalViewProps) => { }); return false; } - if ( - keyutil.checkKeyPressed(waveEvent, "Ctrl:Shift:ArrowLeft") || - keyutil.checkKeyPressed(waveEvent, "Ctrl:Shift:ArrowRight") || - keyutil.checkKeyPressed(waveEvent, "Ctrl:Shift:ArrowUp") || - keyutil.checkKeyPressed(waveEvent, "Ctrl:Shift:ArrowDown") - ) { - return false; - } - for (let i = 1; i <= 9; i++) { - if ( - keyutil.checkKeyPressed(waveEvent, `Ctrl:Shift:c{Digit${i}}`) || - keyutil.checkKeyPressed(waveEvent, `Ctrl:Shift:c{Numpad${i}}`) - ) { - return false; - } - } if (keyutil.checkKeyPressed(waveEvent, "Ctrl:Shift:v")) { const p = navigator.clipboard.readText(); p.then((text) => { termRef.current?.terminal.paste(text); - // termRef.current?.handleTermData(text); }); event.preventDefault(); event.stopPropagation(); - return true; + return false; } else if (keyutil.checkKeyPressed(waveEvent, "Ctrl:Shift:c")) { const sel = termRef.current?.terminal.getSelection(); navigator.clipboard.writeText(sel); event.preventDefault(); event.stopPropagation(); - return true; + return false; } if (shellProcStatusRef.current != "running" && keyutil.checkKeyPressed(waveEvent, "Enter")) { // restart @@ -313,12 +298,10 @@ const TerminalView = ({ blockId, model }: TerminalViewProps) => { prtn.catch((e) => console.log("error controller resync (enter)", blockId, e)); return false; } - if (PLATFORM == "win32" || PLATFORM == "linux") { - const reservedCmdKeys = ["Cmd:t", "Cmd:n", "Cmd:w", "Cmd:m", "Cmd:g", "Cmd:[", "Cmd:]", "Cmd:Shift:r"]; - for (let i = 0; i < reservedCmdKeys.length; i++) { - if (keyutil.checkKeyPressed(waveEvent, reservedCmdKeys[i])) { - return false; - } + const globalKeys = getAllGlobalKeyBindings(); + for (const key of globalKeys) { + if (keyutil.checkKeyPressed(waveEvent, key)) { + return false; } } return true;