mirror of
https://github.com/wavetermdev/waveterm.git
synced 2024-12-22 16:48: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 * as services from "@/app/store/services";
|
||||||
import { MagnifyIcon } from "@/element/magnify";
|
import { MagnifyIcon } from "@/element/magnify";
|
||||||
import { useLayoutModel } from "@/layout/index";
|
import { useLayoutModel } from "@/layout/index";
|
||||||
import { adaptFromReactOrNativeKeyEvent, checkKeyPressed } from "@/util/keyutil";
|
import { checkKeyPressed, keydownWrapper } from "@/util/keyutil";
|
||||||
import * as util from "@/util/util";
|
import * as util from "@/util/util";
|
||||||
import clsx from "clsx";
|
import clsx from "clsx";
|
||||||
import * as jotai from "jotai";
|
import * as jotai from "jotai";
|
||||||
@ -258,13 +258,15 @@ const BlockFrame_Default_Component = (props: BlockFrameProps) => {
|
|||||||
|
|
||||||
const viewIconElem = getViewIconElem(viewIconUnion, blockData);
|
const viewIconElem = getViewIconElem(viewIconUnion, blockData);
|
||||||
|
|
||||||
function handleKeyDown(e: React.KeyboardEvent<HTMLDivElement>) {
|
function handleKeyDown(waveEvent: WaveKeyboardEvent): boolean {
|
||||||
const waveEvent = adaptFromReactOrNativeKeyEvent(e);
|
|
||||||
if (checkKeyPressed(waveEvent, "Cmd:m")) {
|
if (checkKeyPressed(waveEvent, "Cmd:m")) {
|
||||||
e.preventDefault();
|
|
||||||
layoutModel?.onMagnifyToggle();
|
layoutModel?.onMagnifyToggle();
|
||||||
return;
|
return true;
|
||||||
}
|
}
|
||||||
|
if (viewModel?.keyDownHandler) {
|
||||||
|
return viewModel.keyDownHandler(waveEvent);
|
||||||
|
}
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
const innerStyle: React.CSSProperties = {};
|
const innerStyle: React.CSSProperties = {};
|
||||||
if (!preview && customBg?.bg != null) {
|
if (!preview && customBg?.bg != null) {
|
||||||
@ -290,7 +292,7 @@ const BlockFrame_Default_Component = (props: BlockFrameProps) => {
|
|||||||
onClick={blockModel?.onClick}
|
onClick={blockModel?.onClick}
|
||||||
onFocusCapture={blockModel?.onFocusCapture}
|
onFocusCapture={blockModel?.onFocusCapture}
|
||||||
ref={blockModel?.blockRef}
|
ref={blockModel?.blockRef}
|
||||||
onKeyDown={handleKeyDown}
|
onKeyDown={keydownWrapper(handleKeyDown)}
|
||||||
>
|
>
|
||||||
<BlockMask blockId={blockId} preview={preview} isFocused={isFocused} />
|
<BlockMask blockId={blockId} preview={preview} isFocused={isFocused} />
|
||||||
<div className="block-frame-default-inner" style={innerStyle}>
|
<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;
|
onSearch?: (text: string) => void;
|
||||||
getSettingsMenuItems?: () => ContextMenuItem[];
|
getSettingsMenuItems?: () => ContextMenuItem[];
|
||||||
giveFocus?: () => boolean;
|
giveFocus?: () => boolean;
|
||||||
|
keyDownHandler?: (e: WaveKeyboardEvent) => boolean;
|
||||||
}
|
}
|
||||||
|
|
||||||
type UpdaterStatus = "up-to-date" | "checking" | "downloading" | "ready" | "error" | "installing";
|
type UpdaterStatus = "up-to-date" | "checking" | "downloading" | "ready" | "error" | "installing";
|
||||||
|
Loading…
Reference in New Issue
Block a user