// 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. constregistry = this.pluginSystem.findInterface( Editor.IContextActionRegistry.interfaceId ) asEditor.IContextActionRegistry;
constaction = newEditor.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. constguard = registry.registerAction((_ctx: Editor.IContext) => { action.apply(); returnundefinedasunknownasEditor; }); this.guards.push(guard);
An action in a Editor.IContextActionRegistry.
Example