Skip to main content

Editor.ContextAction

Class

An action in a Editor.IContextActionRegistry.

Index

Example

// Define a ContextAction and hand it to the context-action registry so it
// shows up in the right-click menu. registerAction expects a callback; use
// the ContextAction's id/caption/group to describe what gets rendered.
const registry = this.pluginSystem.findInterface(
Editor.IContextActionRegistry.interfaceId
) as Editor.IContextActionRegistry;

const action = new Editor.ContextAction();
action.id = 'my-plugin.greet';
action.caption = 'Say Hello';
action.description = 'Prints a greeting to the console';
action.group = ['My Plugin', 'Utilities'];
action.apply = () => {
console.log(`[${action.id}] Hello from context action!`);
};

// Wire the action into the registry. Dispose the guard in stop() to unregister.
const guard = registry.registerAction((_ctx: Editor.IContext) => {
action.apply();
return undefined as unknown as Editor;
});
this.guards.push(guard);

Constructors

Constructor

new ContextAction(): ContextAction

Create a new context action.

Returns

ContextAction

Properties

apply

apply: () => void

Callback for when the action is executed.

Returns

void


caption

caption: string

Caption for the action.


description

description: string

Description for the action.


group

group: string[]

Section for the action to be in.


id

id: string

Identifier for the caption.