API to access the "Rename heading" functionality?

If you open the context menu while the cursor is on a heading, there’s an option to “Rename heading”, which has the benefit of updating links to that heading. Is there a way to access that functionality via API?

(I am the author of the number-headings-obsidian plugin GitHub - onlyafly/number-headings-obsidian: Automatically number headings in a document in Obsidian and would like to add some functionality to update links to headings when the numbering is updated.)

4 Likes

Bump. I also need this functionality.

1 Like

I think it’s not officially available, but you can find out what’s happening there by searching app.js by renameHeading. It might be possible to access the underlying mechanism from your plugin by monkey-patching.

But as for heading numbering, I would take another approach that doesn’t hard-code them directly into notes: heading numbers can be computed/derived from the note content and can be displayed without actually modifying it.

2 Likes

app.js? where would one find that?

The closest you can get is

app.commands.executeCommandById('editor:rename-heading')
3 Likes

oh wow that actually works in the console!

I wonder if we could finally build a rename heading plugin, something that displays a little clickable item beside the headings and lets you use that (and act as a reminder) instead of the right click menu.

For anyone who isn’t familiar with the purpose of the rename heading option, it’s so that links to it get updated. Otherwise links and embeddings in other notes fail.

It’s a big problem and honestly the right click menu option is not prominent or accessible enough for something so important and frequently used

Does anyone know how to make some kind of clickable button with this command appear at the end of or somewhere near headings?

There’s a plugin I use on tablet where I can’t use right clicks:

I almost missed seeing this.
So much easier to add this to a Templater script…

<%*
app.commands.executeCommandById("editor:rename-heading");
_%>

…and add this command to the Command Palette or mobile toolbar, or on PC bind a hotkey to it.

@Yurcee To avoid any misunderstanding, let me explain further. Any right-click menu operation will cause the v1.7.4 editing popover to disappear. You don’t need to install any plugins; you can test this in the Sandbox Vault. Some people who have installed my plugin might think it is causing this issue, but that’s not the case. Similarly, this behavior has nothing to do with the API itself; it is a feature of the new version of the v1.7.4 editing popover.