How to delete footnote reference from the editor menu #478
-
|
I adore using toolbars for the editor menu. I've just run into one problem, deleting footnotes and their reference. Obsidian has a build-in option for this in the editor menu. Just right-click anywhere in the footnote and you can delete it and the reference. But it is not a command we can access. While my javascript experience is quite lacking, I know enough that I can make a command to delete the reference. If I have the footnote number. Extracting that number is the problem. Would appreciate it if anyone more familiar with this than me had a suggestion for how to do it. |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 1 reply
-
|
@Maja-Nune Thanks for the feedback! I was able to inspect the code for Try this:
const e = ntb.app.workspace.activeLeaf.view?.editor;
const f = ntb.app.workspace.getActiveFile();
if (!f) return;
const ref = e.getClickableTokenAt(e.getCursor());
if (!ref || ref.type !== 'footref') return;
const c = ntb.app.metadataCache.getFileCache(f);
const fn = c?.footnotes?.find(f => f.id === ref.text);
if (!fn) return;
e.transaction({
changes: [
{ from: ref.start, to: ref.end, text: "" },
{
from: e.offsetToPos(fn.position.start.offset - 1),
to: e.offsetToPos(fn.position.end.offset),
text: ""
}
]
}); |
Beta Was this translation helpful? Give feedback.
@Maja-Nune Thanks for the feedback!
I was able to inspect the code for
Delete footnote and reference, provided it to AI (Claude), and tweaked it to work with Note Toolbar. This code seems to work!Try this: