obsidian-api
obsidian-api copied to clipboard
Expose an API to handle multiple cursors programmatically
I am trying to develop a functionality similar to pycharm's or sublime text's multiple selections (when you select some text, press hotkey and capture the following occurrences of the text, getting a way to edit multiple instances of the text).
Multiple cursor functionality is available in the Obsidian (https://help.obsidian.md/How+to/Working+with+multiple+cursors) from the UI but I see no quick way to achieve that programmatically.
The only way to create cursors is by using the setCursor method but it does not allow creating multiple cursors
/** Set the cursor position. You can either pass a single {line, ch} object, or the line and the character as two separate parameters.
Will replace all selections with a single, empty selection at the given position.
The supported options are the same as for setSelection */
setCursor(
pos: CodeMirror.Position | number,
ch?: number,
options?: { bias?: number; origin?: string; scroll?: boolean },
): void;
this code sample
editor.setCursor(
{ line: cursorStart.line, ch: cursorStart.ch + 2 },
)
editor.setCursor(
{ line: cursorStart.line, ch: cursorStart.ch + 5 },
)
editor.setCursor(
{ line: cursorStart.line, ch: cursorStart.ch + 8 },
)
obviously just sets the cursor to the latest value.
Thanks
@MrLokans I had the same exact request! Check https://discord.com/channels/686053708261228577/707816848615407697/831885870511554560 for the discussion I had with Licat.
Will add an API for this in the next release.
@lishid thanks a lot!