diff --git a/docs/en/guide/shortcut-custom.md b/docs/en/guide/shortcut-custom.md index e3cf04a..2829cf6 100644 --- a/docs/en/guide/shortcut-custom.md +++ b/docs/en/guide/shortcut-custom.md @@ -15,7 +15,8 @@ instance.register.shortcutList([ shift?: boolean; alt?: boolean; isGlobal?: boolean; - callback: (command: Command) => any; + callback?: (command: Command) => any; + disable?: boolean; } ]) ``` diff --git a/docs/guide/shortcut-custom.md b/docs/guide/shortcut-custom.md index 12d3ca4..dce51ca 100644 --- a/docs/guide/shortcut-custom.md +++ b/docs/guide/shortcut-custom.md @@ -15,7 +15,8 @@ instance.register.shortcutList([ shift?: boolean; alt?: boolean; isGlobal?: boolean; - callback: (command: Command) => any; + callback?: (command: Command) => any; + disable?: boolean; } ]) ``` diff --git a/src/editor/core/shortcut/Shortcut.ts b/src/editor/core/shortcut/Shortcut.ts index dcf8f88..86ae425 100644 --- a/src/editor/core/shortcut/Shortcut.ts +++ b/src/editor/core/shortcut/Shortcut.ts @@ -33,12 +33,12 @@ export class Shortcut { } private _addShortcutList(payload: IRegisterShortcut[]) { - for (let s = 0; s < payload.length; s++) { + for (let s = payload.length - 1; s >= 0; s--) { const shortCut = payload[s] if (shortCut.isGlobal) { - this.globalShortcutList.push(shortCut) + this.globalShortcutList.unshift(shortCut) } else { - this.agentShortcutList.push(shortCut) + this.agentShortcutList.unshift(shortCut) } } } @@ -69,8 +69,10 @@ export class Shortcut { evt.altKey === !!shortCut.alt && evt.key === shortCut.key ) { - shortCut.callback(this.command) - evt.preventDefault() + if (!shortCut.disable) { + shortCut?.callback?.(this.command) + evt.preventDefault() + } break } } diff --git a/src/editor/interface/shortcut/Shortcut.ts b/src/editor/interface/shortcut/Shortcut.ts index d224c2b..0ceb07d 100644 --- a/src/editor/interface/shortcut/Shortcut.ts +++ b/src/editor/interface/shortcut/Shortcut.ts @@ -9,5 +9,6 @@ export interface IRegisterShortcut { shift?: boolean alt?: boolean // windows:alt || mac:option isGlobal?: boolean - callback: (command: Command) => any + callback?: (command: Command) => any + disable?: boolean }