Applies to :
PowerDocs for Linux
PowerDocs for Windows
Class `Editor`
The Editor class (accessed via context.editor) enables extensions to add contextual actions to the PowerDocs editor.
Properties
Editor does not expose public properties.
Methods
registerSelectionAction(actionDescriptor)
Registers a contextual action that appears when text is selected in the Markdown editor.
Parameters
actionDescriptor(object): Configuration object for the selection action.
| Field | Type | Required | Description |
|---|---|---|---|
id |
string |
Yes | Unique identifier for the action (e.g., 'translate-selection'). |
title |
string |
Yes | Text label displayed on the action button or tooltip. |
icon / iconName |
string |
No | Name of the icon to display (e.g., 'Sparkle', 'Globe', 'Copy', 'TextBulletList'). Defaults to 'Sparkle'. |
execute |
function(selection) |
Yes | Function called when the user clicks the action button. |
Callback Parameter for execute(selection)
selection(SelectionContext): Provides the selected text (selection.text), text replacement (selection.replaceText(newText)), and text insertion (selection.insertText(newText)) with full Undo/Redo integration.
Examples
1. Web Search Action
export function activate(context) {
context.editor.registerSelectionAction({
id: 'search-google',
title: 'Search on Google',
icon: 'Globe',
execute: (selection) => {
const query = encodeURIComponent(selection.text.trim());
context.env.openUrl(`https://www.google.com/search?q=${query}`);
}
});
}
2. Text Transformation Action (Uppercase / Lowercase / Title Case)
export function activate(context) {
// Convert selection to uppercase
context.editor.registerSelectionAction({
id: 'format-uppercase',
title: 'UPPERCASE',
icon: 'TextCaseUppercase',
execute: (selection) => {
selection.replaceText(selection.text.toUpperCase());
}
});
// Convert selection to Title Case
context.editor.registerSelectionAction({
id: 'format-titlecase',
title: 'Title Case',
icon: 'TextCaseTitle',
execute: (selection) => {
const titleCase = selection.text.replace(
/\w\S*/g,
(txt) => txt.charAt(0).toUpperCase() + txt.substr(1).toLowerCase()
);
selection.replaceText(titleCase);
}
});
}
3. Wrap Selection with a Markdown Custom Container
export function activate(context) {
context.editor.registerSelectionAction({
id: 'wrap-in-alert',
title: 'Wrap in Warning Block',
icon: 'Warning',
execute: (selection) => {
const wrapped = `::: DONT Important Notice\n${selection.text}\n:::\n`;
selection.replaceText(wrapped);
}
});
}