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);
}
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,

View File

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