fix term keydown handler

This commit is contained in:
sawka 2024-08-19 12:24:08 -07:00
parent b412f72f6b
commit 3f37837394
4 changed files with 32 additions and 10 deletions

View File

@ -405,19 +405,19 @@ const AppKeyHandlers = () => {
return true;
}
}
if (keyutil.checkKeyPressed(waveEvent, "Cmd:ArrowUp")) {
if (keyutil.checkKeyPressed(waveEvent, "Ctrl:Shift:ArrowUp")) {
switchBlock(tabId, 0, -1);
return true;
}
if (keyutil.checkKeyPressed(waveEvent, "Cmd:ArrowDown")) {
if (keyutil.checkKeyPressed(waveEvent, "Ctrl:Shift:ArrowDown")) {
switchBlock(tabId, 0, 1);
return true;
}
if (keyutil.checkKeyPressed(waveEvent, "Cmd:ArrowLeft")) {
if (keyutil.checkKeyPressed(waveEvent, "Ctrl:Shift:ArrowLeft")) {
switchBlock(tabId, -1, 0);
return true;
}
if (keyutil.checkKeyPressed(waveEvent, "Cmd:ArrowRight")) {
if (keyutil.checkKeyPressed(waveEvent, "Ctrl:Shift:ArrowRight")) {
switchBlock(tabId, 1, 0);
return true;
}

View File

@ -100,7 +100,14 @@ function callBackendService(service: string, method: string, args: any[], noUICo
if (respData.error != null) {
throw new Error(`call ${methodName} error: ${respData.error}`);
}
console.log("Call", methodName, Date.now() - startTs + "ms");
const durationStr = Date.now() - startTs + "ms";
if (methodName == "object.UpdateObject") {
console.log("Call UpdateObject", args[0].otype, args[0].oid, durationStr, args[0]);
} else if (methodName == "object.GetObject") {
console.log("Call GetObject", args[0], durationStr);
} else {
console.log("Call", methodName, durationStr);
}
return respData.data;
});
return prtn;

View File

@ -217,7 +217,7 @@ const TerminalView = ({ blockId, model }: TerminalViewProps) => {
const isFocused = jotai.useAtomValue(isFocusedAtom);
React.useEffect(() => {
function handleTerminalKeydown(event: KeyboardEvent) {
function handleTerminalKeydown(event: KeyboardEvent): boolean {
const waveEvent = keyutil.adaptFromReactOrNativeKeyEvent(event);
if (keyutil.checkKeyPressed(waveEvent, "Cmd:Escape")) {
event.preventDefault();
@ -225,11 +225,28 @@ const TerminalView = ({ blockId, model }: TerminalViewProps) => {
WshServer.SetMetaCommand({ oref: WOS.makeORef("block", blockId), meta: { "term:mode": null } });
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:Digit${i}`) ||
keyutil.checkKeyPressed(waveEvent, `Ctrl:Shift:c{Numpad${i}}`)
) {
return false;
}
}
if (shellProcStatusRef.current != "running" && keyutil.checkKeyPressed(waveEvent, "Enter")) {
// restart
WshServer.ControllerRestartCommand({ blockid: blockId });
return false;
}
return true;
}
const settings = globalStore.get(atoms.settingsConfigAtom);
const termTheme = computeTheme(settings, blockData?.meta?.["term:theme"]);

View File

@ -32,7 +32,7 @@ const WebGLSupported = detectWebGLSupport();
let loggedWebGL = false;
type TermWrapOptions = {
keydownHandler?: (e: KeyboardEvent) => void;
keydownHandler?: (e: KeyboardEvent) => boolean;
useWebGl?: boolean;
};
@ -49,7 +49,6 @@ export class TermWrap {
heldData: Uint8Array[];
handleResize_debounced: () => void;
isRunning: boolean;
keydownHandler: (e: KeyboardEvent) => void;
constructor(
blockId: string,
@ -116,6 +115,7 @@ export class TermWrap {
}, 0);
return true;
});
this.terminal.attachCustomKeyEventHandler(waveOptions.keydownHandler);
this.connectElem = connectElem;
this.mainFileSubject = null;
this.heldData = [];
@ -123,11 +123,9 @@ export class TermWrap {
this.terminal.open(this.connectElem);
this.handleResize();
this.isRunning = true;
this.keydownHandler = waveOptions.keydownHandler;
}
async initTerminal() {
this.connectElem.addEventListener("keydown", this.keydownHandler, true);
this.terminal.onData(this.handleTermData.bind(this));
this.mainFileSubject = getFileSubject(this.blockId, TermFileName);
this.mainFileSubject.subscribe(this.handleNewFileSubjectData.bind(this));