Getting the currently selected text when creating an Obsidian plugin…
You can also update selected text…
Byte sized tech know-how.
Getting the currently selected text when creating an Obsidian plugin…
import { MarkdownView } from 'obsidian';
// ...
// Access to the editor component...
const editor = this.app.workspace.getActiveViewOfType(MarkdownView)?.editor;
const selectedText = editor.getSelection(); // Get selected text
You can also update selected text…
editor.replaceSelection("New Text Goes Here");
Copyright © 2025 Txt