have terminal ignore all global keybindings (#924)

This commit is contained in:
Mike Sawka 2024-10-01 14:07:28 -07:00 committed by GitHub
parent b7ef20d6fd
commit f21045d8dd
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 15 additions and 26 deletions

View File

@ -282,6 +282,11 @@ function registerGlobalKeys() {
getApi().registerGlobalWebviewKeys(allKeys); 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. // these keyboard events happen *anywhere*, even if you have focus in an input or somewhere else.
function handleGlobalWaveKeyboardEvents(waveEvent: WaveKeyboardEvent): boolean { function handleGlobalWaveKeyboardEvents(waveEvent: WaveKeyboardEvent): boolean {
for (const key of globalKeyMap.keys()) { for (const key of globalKeyMap.keys()) {
@ -297,6 +302,7 @@ function handleGlobalWaveKeyboardEvents(waveEvent: WaveKeyboardEvent): boolean {
export { export {
appHandleKeyDown, appHandleKeyDown,
getAllGlobalKeyBindings,
getSimpleControlShiftAtom, getSimpleControlShiftAtom,
registerControlShiftStateUpdateHandler, registerControlShiftStateUpdateHandler,
registerElectronReinjectKeyHandler, registerElectronReinjectKeyHandler,

View File

@ -1,11 +1,12 @@
// Copyright 2024, Command Line Inc. // Copyright 2024, Command Line Inc.
// SPDX-License-Identifier: Apache-2.0 // SPDX-License-Identifier: Apache-2.0
import { getAllGlobalKeyBindings } from "@/app/store/keymodel";
import { waveEventSubscribe } from "@/app/store/wps"; import { waveEventSubscribe } from "@/app/store/wps";
import { RpcApi } from "@/app/store/wshclientapi"; import { RpcApi } from "@/app/store/wshclientapi";
import { WindowRpcClient } from "@/app/store/wshrpcutil"; import { WindowRpcClient } from "@/app/store/wshrpcutil";
import { VDomView } from "@/app/view/term/vdom"; 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 services from "@/store/services";
import * as keyutil from "@/util/keyutil"; import * as keyutil from "@/util/keyutil";
import * as util from "@/util/util"; import * as util from "@/util/util";
@ -265,6 +266,7 @@ const TerminalView = ({ blockId, model }: TerminalViewProps) => {
if (waveEvent.type != "keydown") { if (waveEvent.type != "keydown") {
return true; return true;
} }
// deal with terminal specific keybindings
if (keyutil.checkKeyPressed(waveEvent, "Cmd:Escape")) { if (keyutil.checkKeyPressed(waveEvent, "Cmd:Escape")) {
event.preventDefault(); event.preventDefault();
event.stopPropagation(); event.stopPropagation();
@ -274,37 +276,20 @@ const TerminalView = ({ blockId, model }: TerminalViewProps) => {
}); });
return false; 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")) { if (keyutil.checkKeyPressed(waveEvent, "Ctrl:Shift:v")) {
const p = navigator.clipboard.readText(); const p = navigator.clipboard.readText();
p.then((text) => { p.then((text) => {
termRef.current?.terminal.paste(text); termRef.current?.terminal.paste(text);
// termRef.current?.handleTermData(text);
}); });
event.preventDefault(); event.preventDefault();
event.stopPropagation(); event.stopPropagation();
return true; return false;
} else if (keyutil.checkKeyPressed(waveEvent, "Ctrl:Shift:c")) { } else if (keyutil.checkKeyPressed(waveEvent, "Ctrl:Shift:c")) {
const sel = termRef.current?.terminal.getSelection(); const sel = termRef.current?.terminal.getSelection();
navigator.clipboard.writeText(sel); navigator.clipboard.writeText(sel);
event.preventDefault(); event.preventDefault();
event.stopPropagation(); event.stopPropagation();
return true; return false;
} }
if (shellProcStatusRef.current != "running" && keyutil.checkKeyPressed(waveEvent, "Enter")) { if (shellProcStatusRef.current != "running" && keyutil.checkKeyPressed(waveEvent, "Enter")) {
// restart // restart
@ -313,14 +298,12 @@ const TerminalView = ({ blockId, model }: TerminalViewProps) => {
prtn.catch((e) => console.log("error controller resync (enter)", blockId, e)); prtn.catch((e) => console.log("error controller resync (enter)", blockId, e));
return false; return false;
} }
if (PLATFORM == "win32" || PLATFORM == "linux") { const globalKeys = getAllGlobalKeyBindings();
const reservedCmdKeys = ["Cmd:t", "Cmd:n", "Cmd:w", "Cmd:m", "Cmd:g", "Cmd:[", "Cmd:]", "Cmd:Shift:r"]; for (const key of globalKeys) {
for (let i = 0; i < reservedCmdKeys.length; i++) { if (keyutil.checkKeyPressed(waveEvent, key)) {
if (keyutil.checkKeyPressed(waveEvent, reservedCmdKeys[i])) {
return false; return false;
} }
} }
}
return true; return true;
} }
const fullConfig = globalStore.get(atoms.fullConfigAtom); const fullConfig = globalStore.get(atoms.fullConfigAtom);