How to edit a selected text inside of a plugin?

I know that I can get the selected text from a note

//Get selected text
const selectedText = (await joplin.commands.execute('selectedText') as string);

//Get active note
const note = await joplin.workspace.selectedNote();

but then how can I edit the text? Should I edit it and then assign new note text to note body like

note.body = editedText;


UPDATE: I guess I should use sth like['notes', joplin.workspace.selectedNoteIds[0]], null, { body: editedText });
1 Like

That would be the best way to do it if it works for you.

The alternative is to use an editor command directly. But that will break if Joplin ever switches editors.

I have noticed that using doesn't update the text displayed in the editor until switching away to a different note and then back again. Is there a way to refresh the editor after using this call?

Disregard this. I found I can do what I want better with a ContentScript.

1 Like