11/* eslint-disable max-len */
2- import { Editor , globalContext } from '@alilc/lowcode-editor-core' ;
32import { isFormEvent } from '@alilc/lowcode-utils' ;
43import {
54 focusing ,
@@ -12,22 +11,8 @@ import {
1211 IPublicModelNode ,
1312} from '@alilc/lowcode-types' ;
1413import symbols from '../modules/symbols' ;
15- const { nodeSymbol, documentSymbol } = symbols ;
16-
17- export function isInLiveEditing ( ) {
18- const workspace = globalContext . has ( 'workspace' ) && globalContext . get ( 'workspace' ) ;
19- if ( workspace ?. isActive ) {
20- return Boolean (
21- workspace . window . editor . get ( 'designer' ) ?. project ?. simulator ?. liveEditing ?. editing ,
22- ) ;
23- }
2414
25- if ( globalContext . has ( Editor ) ) {
26- return Boolean (
27- globalContext . get ( Editor ) . get ( 'designer' ) ?. project ?. simulator ?. liveEditing ?. editing ,
28- ) ;
29- }
30- }
15+ const { nodeSymbol, documentSymbol } = symbols ;
3116
3217/* istanbul ignore next */
3318function getNextForSelect ( next : IPublicModelNode | null , head ?: any , parent ?: IPublicModelNode | null ) : any {
@@ -95,12 +80,12 @@ function getPrevForSelect(prev: IPublicModelNode | null, head?: any, parent?: IP
9580export const builtinHotkey = ( ctx : IPublicModelPluginContext ) => {
9681 return {
9782 init ( ) {
98- const { hotkey, project, logger } = ctx ;
83+ const { hotkey, project, logger, canvas } = ctx ;
9984 // hotkey binding
10085 hotkey . bind ( [ 'backspace' , 'del' ] , ( e : KeyboardEvent , action ) => {
10186 logger . info ( `action ${ action } is triggered` ) ;
10287
103- if ( isInLiveEditing ( ) ) {
88+ if ( canvas . isInLiveEditing ) {
10489 return ;
10590 }
10691 // TODO: use focus-tracker
@@ -124,7 +109,7 @@ export const builtinHotkey = (ctx: IPublicModelPluginContext) => {
124109 hotkey . bind ( 'escape' , ( e : KeyboardEvent , action ) => {
125110 logger . info ( `action ${ action } is triggered` ) ;
126111 // const currentFocus = focusing.current;
127- if ( isInLiveEditing ( ) ) {
112+ if ( canvas . isInLiveEditing ) {
128113 return ;
129114 }
130115 const sel = focusing . focusDesigner ?. currentDocument ?. selection ;
@@ -140,7 +125,7 @@ export const builtinHotkey = (ctx: IPublicModelPluginContext) => {
140125 // command + c copy command + x cut
141126 hotkey . bind ( [ 'command+c' , 'ctrl+c' , 'command+x' , 'ctrl+x' ] , ( e , action ) => {
142127 logger . info ( `action ${ action } is triggered` ) ;
143- if ( isInLiveEditing ( ) ) {
128+ if ( canvas . isInLiveEditing ) {
144129 return ;
145130 }
146131 const doc = project . currentDocument ;
@@ -179,10 +164,9 @@ export const builtinHotkey = (ctx: IPublicModelPluginContext) => {
179164 // command + v paste
180165 hotkey . bind ( [ 'command+v' , 'ctrl+v' ] , ( e , action ) => {
181166 logger . info ( `action ${ action } is triggered` ) ;
182- if ( isInLiveEditing ( ) ) {
167+ if ( canvas . isInLiveEditing ) {
183168 return ;
184169 }
185- if ( isInLiveEditing ( ) ) return ;
186170 // TODO
187171 const designer = focusing . focusDesigner ;
188172 const doc = project ?. currentDocument ;
@@ -212,7 +196,7 @@ export const builtinHotkey = (ctx: IPublicModelPluginContext) => {
212196 // command + z undo
213197 hotkey . bind ( [ 'command+z' , 'ctrl+z' ] , ( e , action ) => {
214198 logger . info ( `action ${ action } is triggered` ) ;
215- if ( isInLiveEditing ( ) ) {
199+ if ( canvas . isInLiveEditing ) {
216200 return ;
217201 }
218202 const history = project . currentDocument ?. history ;
@@ -230,7 +214,7 @@ export const builtinHotkey = (ctx: IPublicModelPluginContext) => {
230214 // command + shift + z redo
231215 hotkey . bind ( [ 'command+y' , 'ctrl+y' , 'command+shift+z' ] , ( e , action ) => {
232216 logger . info ( `action ${ action } is triggered` ) ;
233- if ( isInLiveEditing ( ) ) {
217+ if ( canvas . isInLiveEditing ) {
234218 return ;
235219 }
236220 const history = project . currentDocument ?. history ;
@@ -247,7 +231,7 @@ export const builtinHotkey = (ctx: IPublicModelPluginContext) => {
247231 // sibling selection
248232 hotkey . bind ( [ 'left' , 'right' ] , ( e , action ) => {
249233 logger . info ( `action ${ action } is triggered` ) ;
250- if ( isInLiveEditing ( ) ) {
234+ if ( canvas . isInLiveEditing ) {
251235 return ;
252236 }
253237 const doc = project . currentDocument ;
@@ -266,7 +250,7 @@ export const builtinHotkey = (ctx: IPublicModelPluginContext) => {
266250
267251 hotkey . bind ( [ 'up' , 'down' ] , ( e , action ) => {
268252 logger . info ( `action ${ action } is triggered` ) ;
269- if ( isInLiveEditing ( ) ) {
253+ if ( canvas . isInLiveEditing ) {
270254 return ;
271255 }
272256 const doc = project . currentDocument ;
@@ -291,7 +275,7 @@ export const builtinHotkey = (ctx: IPublicModelPluginContext) => {
291275
292276 hotkey . bind ( [ 'option+left' , 'option+right' ] , ( e , action ) => {
293277 logger . info ( `action ${ action } is triggered` ) ;
294- if ( isInLiveEditing ( ) ) {
278+ if ( canvas . isInLiveEditing ) {
295279 return ;
296280 }
297281 const doc = project . currentDocument ;
@@ -325,7 +309,7 @@ export const builtinHotkey = (ctx: IPublicModelPluginContext) => {
325309
326310 hotkey . bind ( [ 'option+up' ] , ( e , action ) => {
327311 logger . info ( `action ${ action } is triggered` ) ;
328- if ( isInLiveEditing ( ) ) {
312+ if ( canvas . isInLiveEditing ) {
329313 return ;
330314 }
331315 const doc = project . currentDocument ;
@@ -367,7 +351,7 @@ export const builtinHotkey = (ctx: IPublicModelPluginContext) => {
367351
368352 hotkey . bind ( [ 'option+down' ] , ( e , action ) => {
369353 logger . info ( `action ${ action } is triggered` ) ;
370- if ( isInLiveEditing ( ) ) {
354+ if ( canvas . isInLiveEditing ) {
371355 return ;
372356 }
373357 const doc = project . getCurrentDocument ( ) ;
0 commit comments