Using Editor outside of editorCallback

Hello, I’ve been trying to use a Modal Suggestive menu to insert text but I can’t figure out how to insert a new piece of text at the cursorposition when the user chooses an option.
I want to make a menu wich is reachable via a ribbon with a SuggestModal where the user can shoose between multiple options and when he chooses an option, it adds a certain piece of text, saved with the option, at the cursorposition.

You may want to check this line in console.


It’s mentioned in the docs:

If you want to use the editor elsewhere, you can access it from the active view:

As for @Acylation’s answer, activeEditor can be null so you will need an optional chaining in your plugin (of course it’s not a big deal when just playing around in the console):

const editor = app.workspace.activeEditor?.editor
if (editor) {
    // do something
1 Like