mirror of
https://github.com/wavetermdev/waveterm.git
synced 2024-12-21 16:38:23 +01:00
implement a viewmodel keydown handler
This commit is contained in:
parent
f535c5c1ab
commit
9a06b43266
@ -8,7 +8,7 @@ import { atoms, globalStore, useBlockAtom, WOS } from "@/app/store/global";
|
||||
import * as services from "@/app/store/services";
|
||||
import { MagnifyIcon } from "@/element/magnify";
|
||||
import { useLayoutModel } from "@/layout/index";
|
||||
import { adaptFromReactOrNativeKeyEvent, checkKeyPressed } from "@/util/keyutil";
|
||||
import { checkKeyPressed, keydownWrapper } from "@/util/keyutil";
|
||||
import * as util from "@/util/util";
|
||||
import clsx from "clsx";
|
||||
import * as jotai from "jotai";
|
||||
@ -258,13 +258,15 @@ const BlockFrame_Default_Component = (props: BlockFrameProps) => {
|
||||
|
||||
const viewIconElem = getViewIconElem(viewIconUnion, blockData);
|
||||
|
||||
function handleKeyDown(e: React.KeyboardEvent<HTMLDivElement>) {
|
||||
const waveEvent = adaptFromReactOrNativeKeyEvent(e);
|
||||
function handleKeyDown(waveEvent: WaveKeyboardEvent): boolean {
|
||||
if (checkKeyPressed(waveEvent, "Cmd:m")) {
|
||||
e.preventDefault();
|
||||
layoutModel?.onMagnifyToggle();
|
||||
return;
|
||||
return true;
|
||||
}
|
||||
if (viewModel?.keyDownHandler) {
|
||||
return viewModel.keyDownHandler(waveEvent);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
const innerStyle: React.CSSProperties = {};
|
||||
if (!preview && customBg?.bg != null) {
|
||||
@ -290,7 +292,7 @@ const BlockFrame_Default_Component = (props: BlockFrameProps) => {
|
||||
onClick={blockModel?.onClick}
|
||||
onFocusCapture={blockModel?.onFocusCapture}
|
||||
ref={blockModel?.blockRef}
|
||||
onKeyDown={handleKeyDown}
|
||||
onKeyDown={keydownWrapper(handleKeyDown)}
|
||||
>
|
||||
<BlockMask blockId={blockId} preview={preview} isFocused={isFocused} />
|
||||
<div className="block-frame-default-inner" style={innerStyle}>
|
||||
|
1
frontend/types/custom.d.ts
vendored
1
frontend/types/custom.d.ts
vendored
@ -202,6 +202,7 @@ declare global {
|
||||
onSearch?: (text: string) => void;
|
||||
getSettingsMenuItems?: () => ContextMenuItem[];
|
||||
giveFocus?: () => boolean;
|
||||
keyDownHandler?: (e: WaveKeyboardEvent) => boolean;
|
||||
}
|
||||
|
||||
type UpdaterStatus = "up-to-date" | "checking" | "downloading" | "ready" | "error" | "installing";
|
||||
|
Loading…
Reference in New Issue
Block a user