ObsidianAPI: How can I insert/append text to a specific location, without recreating the whole document?

How do I insert text into a a note at a very specific location in the note?

The method Vault.append() inserts text to the bottom of the note. And Vault.modify() doesn’t exactly insert text, it completely rewrites the whole note into a new string.

I’m not very experienced with TS. I managed to do app.vault.append(currentFile,"\nHello world!") and it worked. I’d like a similar command to insert text.

As for rejecting modify(), maybe my intuition is misguided, but I would rather actually insert text into a specific place, and avoid recreating the whole note. My unthought reasons are: 1. It seems more likely to lead to accidental corruption of the note; 2. Obsidian might not be able to properly understand that the change was small which would be relevant for Obsidian sync; 3. Incompatibility with the cursor: text insertion before the cursor should push it, should just confuse the cursor;

So append,modify,process don’t seem great. I think maybe transaction() and EditorTransaction might be related but I have no idea what they do.

use editor to insert some text:

Outside of using editor specific commands, which do require the file to be open (if I’m not mistaken) you should be using the beforementioned tools like process() in order to preserve “atomic” changes to the file, and locking issues.

Within an editor instance the are more functions available like the replaceRange() and also various tools to read/change the cursor location to your liking.