diff --git a/src/actions/manager.tsx b/src/actions/manager.tsx index cdc4f1f9c..662528f8f 100644 --- a/src/actions/manager.tsx +++ b/src/actions/manager.tsx @@ -117,10 +117,16 @@ export class ActionManager { if (this === undefined) { return []; } + const filter = + opts !== undefined && + ("elements" in opts || "data" in opts || "guardsOnly" in opts); const customActions: Action[] = []; for (const key in this.actions) { const action = this.actions[key]; - if (!isActionName(action.name) && this.isActionEnabled(action, opts)) { + if ( + !isActionName(action.name) && + (!filter || this.isActionEnabled(action, opts)) + ) { customActions.push(action); } } diff --git a/src/components/App.tsx b/src/components/App.tsx index ea706f66a..5cb6c76da 100644 --- a/src/components/App.tsx +++ b/src/components/App.tsx @@ -6241,29 +6241,29 @@ class App extends React.Component { type: "canvas" | "element" | "custom", source?: string, ): ContextMenuItems => { - const options = this._getContextMenuItems(type, source); - return options.filter( + const custom: ContextMenuItems = []; + this.actionManager + .getCustomActions({ data: { source: source ?? "" } }) + .forEach((action) => custom.push(action)); + if (type === "custom") { + return custom; + } + if (custom.length > 0) { + custom.push(CONTEXT_MENU_SEPARATOR); + } + const standard: ContextMenuItems = this._getContextMenuItems(type).filter( (item) => !item || item === CONTEXT_MENU_SEPARATOR || this.actionManager.isActionEnabled(item, { guardsOnly: true }), ); + return [...custom, ...standard]; }; private _getContextMenuItems = ( - type: "canvas" | "element" | "custom", - source?: string, + type: "canvas" | "element", ): ContextMenuItems => { const options: ContextMenuItems = []; - this.actionManager - .getCustomActions({ data: { source: source ?? "" } }) - .forEach((action) => options.push(action)); - if (type === "custom") { - return options; - } - if (options.length > 0) { - options.push(CONTEXT_MENU_SEPARATOR); - } options.push(actionCopyAsPng, actionCopyAsSvg);