From 77fc3f2db281332905092b1617f50bb49311b274 Mon Sep 17 00:00:00 2001 From: JackLian Date: Tue, 13 Dec 2022 14:43:07 +0800 Subject: [PATCH] fix: hotkey should be mounted --- packages/designer/src/document/node/node.ts | 2 +- packages/editor-core/src/hotkey.ts | 4 +- .../src/inner-plugins/builtin-hotkey.ts | 73 ++++++++++++++----- 3 files changed, 58 insertions(+), 21 deletions(-) diff --git a/packages/designer/src/document/node/node.ts b/packages/designer/src/document/node/node.ts index ec6cc811b..b5f2916c6 100644 --- a/packages/designer/src/document/node/node.ts +++ b/packages/designer/src/document/node/node.ts @@ -1018,7 +1018,7 @@ export class Node { } /** - * @deprecated + * TODO: replace non standard metas with standard ones. */ getSuitablePlace(node: Node, ref: any): any { const focusNode = this.document?.focusNode; diff --git a/packages/editor-core/src/hotkey.ts b/packages/editor-core/src/hotkey.ts index 2bb6f2d97..dd1bf97c9 100644 --- a/packages/editor-core/src/hotkey.ts +++ b/packages/editor-core/src/hotkey.ts @@ -368,7 +368,9 @@ export class Hotkey { private nextExpectedAction: boolean | string = false; - constructor(readonly name: string = 'unknown') {} + constructor(readonly name: string = 'unknown') { + this.mount(window); + } mount(window: Window) { const { document } = window; diff --git a/packages/engine/src/inner-plugins/builtin-hotkey.ts b/packages/engine/src/inner-plugins/builtin-hotkey.ts index 9b8b8526d..b42bc1d54 100644 --- a/packages/engine/src/inner-plugins/builtin-hotkey.ts +++ b/packages/engine/src/inner-plugins/builtin-hotkey.ts @@ -89,10 +89,14 @@ function getPrevForSelect(prev: any, head?: any, parent?: any): any { export const builtinHotkey = (ctx: ILowCodePluginContext) => { return { init() { - const { hotkey, project } = ctx; + const { hotkey, project, logger } = ctx; // hotkey binding - hotkey.bind(['backspace', 'del'], (e: KeyboardEvent) => { - if (isInLiveEditing()) return; + hotkey.bind(['backspace', 'del'], (e: KeyboardEvent, action) => { + logger.info(`action ${action} is triggered`); + + if (isInLiveEditing()) { + return; + } // TODO: use focus-tracker const doc = project.currentDocument; if (isFormEvent(e) || !doc) { @@ -111,9 +115,12 @@ export const builtinHotkey = (ctx: ILowCodePluginContext) => { sel.clear(); }); - hotkey.bind('escape', (e: KeyboardEvent) => { + hotkey.bind('escape', (e: KeyboardEvent, action) => { + logger.info(`action ${action} is triggered`); // const currentFocus = focusing.current; - if (isInLiveEditing()) return; + if (isInLiveEditing()) { + return; + } const sel = focusing.focusDesigner?.currentDocument?.selection; if (isFormEvent(e) || !sel) { return; @@ -126,7 +133,10 @@ export const builtinHotkey = (ctx: ILowCodePluginContext) => { // command + c copy command + x cut hotkey.bind(['command+c', 'ctrl+c', 'command+x', 'ctrl+x'], (e, action) => { - if (isInLiveEditing()) return; + logger.info(`action ${action} is triggered`); + if (isInLiveEditing()) { + return; + } const doc = project.currentDocument; if (isFormEvent(e) || !doc) { return; @@ -161,7 +171,11 @@ export const builtinHotkey = (ctx: ILowCodePluginContext) => { }); // command + v paste - hotkey.bind(['command+v', 'ctrl+v'], (e) => { + hotkey.bind(['command+v', 'ctrl+v'], (e, action) => { + logger.info(`action ${action} is triggered`); + if (isInLiveEditing()) { + return; + } if (isInLiveEditing()) return; // TODO const designer = focusing.focusDesigner; @@ -190,8 +204,11 @@ export const builtinHotkey = (ctx: ILowCodePluginContext) => { }); // command + z undo - hotkey.bind(['command+z', 'ctrl+z'], (e) => { - if (isInLiveEditing()) return; + hotkey.bind(['command+z', 'ctrl+z'], (e, action) => { + logger.info(`action ${action} is triggered`); + if (isInLiveEditing()) { + return; + } const history = project.currentDocument?.history; if (isFormEvent(e) || !history) { return; @@ -205,8 +222,11 @@ export const builtinHotkey = (ctx: ILowCodePluginContext) => { }); // command + shift + z redo - hotkey.bind(['command+y', 'ctrl+y', 'command+shift+z'], (e) => { - if (isInLiveEditing()) return; + hotkey.bind(['command+y', 'ctrl+y', 'command+shift+z'], (e, action) => { + logger.info(`action ${action} is triggered`); + if (isInLiveEditing()) { + return; + } const history = project.currentDocument?.history; if (isFormEvent(e) || !history) { return; @@ -220,7 +240,10 @@ export const builtinHotkey = (ctx: ILowCodePluginContext) => { // sibling selection hotkey.bind(['left', 'right'], (e, action) => { - if (isInLiveEditing()) return; + logger.info(`action ${action} is triggered`); + if (isInLiveEditing()) { + return; + } const doc = project.currentDocument; if (isFormEvent(e) || !doc) { return; @@ -236,7 +259,10 @@ export const builtinHotkey = (ctx: ILowCodePluginContext) => { }); hotkey.bind(['up', 'down'], (e, action) => { - if (isInLiveEditing()) return; + logger.info(`action ${action} is triggered`); + if (isInLiveEditing()) { + return; + } const doc = project.currentDocument; if (isFormEvent(e) || !doc) { return; @@ -258,7 +284,10 @@ export const builtinHotkey = (ctx: ILowCodePluginContext) => { }); hotkey.bind(['option+left', 'option+right'], (e, action) => { - if (isInLiveEditing()) return; + logger.info(`action ${action} is triggered`); + if (isInLiveEditing()) { + return; + } const doc = project.currentDocument; if (isFormEvent(e) || !doc) { return; @@ -288,8 +317,11 @@ export const builtinHotkey = (ctx: ILowCodePluginContext) => { } }); - hotkey.bind(['option+up'], (e) => { - if (isInLiveEditing()) return; + hotkey.bind(['option+up'], (e, action) => { + logger.info(`action ${action} is triggered`); + if (isInLiveEditing()) { + return; + } const doc = project.currentDocument; if (isFormEvent(e) || !doc) { return; @@ -326,8 +358,11 @@ export const builtinHotkey = (ctx: ILowCodePluginContext) => { } }); - hotkey.bind(['option+down'], (e) => { - if (isInLiveEditing()) return; + hotkey.bind(['option+down'], (e, action) => { + logger.info(`action ${action} is triggered`); + if (isInLiveEditing()) { + return; + } const doc = project.getCurrentDocument(); if (isFormEvent(e) || !doc) { return; @@ -337,7 +372,7 @@ export const builtinHotkey = (ctx: ILowCodePluginContext) => { if (!selected || selected.length < 1) { return; } - // TODO: 此处需要增加判断当前节点是否可被操作移动,原ve里是用 node.canOperating()来判断 + // TODO: 此处需要增加判断当前节点是否可被操作移动,原 ve 里是用 node.canOperating() 来判断 // TODO: 移动逻辑也需要重新梳理,对于移动目标位置的选择,是否可以移入,需要增加判断 const firstNode = selected[0];