Aidurber / obsidian-plugin-dynamic-toc

An Obsidian plugin for creating Tables of Contents that stay updated with your document
MIT License
269 stars 41 forks source link

Table of contents rendered for active pane, not the note it is for #53

Open tprotopopescu opened 2 years ago

tprotopopescu commented 2 years ago

Since upgrading to obsidian 13.30 the plugin renders the table of contents for whichever note is active, not the note it is intended for.

To reproduce:

Add the table of contents to a note. Open another note in a new pane and switch to it. The table of contents will now show the headings from the active pane. Switch back to the note that has the toc and the headings switch back.

If you click on one of the links in the toc while the other document is active the toc reverts to its proper links (the ones from the intended document) and work as expected.

Tested in the help vault.

Let me know if I can help debug.

claremacrae commented 2 years ago

Thank you for logging this. I cane here to log the same issue.

If you click on one of the links in the toc while the other document is active the toc reverts to its proper links (the ones from the intended document) and work as expected.

I think that workaround only works if the doc with the toc block is not pinned.

If it is pinned, clicking on a link opens a copy of that document in a new pane, which I doubt is ever the intended behaviour.

Aidurber commented 2 years ago

This is a side-effect of the "fix" for #48. With Live Preview, it seems that code blocks share the same processor instance. I've put a few hours into this problem and I can't come up with a solution that fixes both this bug and #48.

Interestingly, for #48 if the codeblock has a different options between notes it renders correctly for the active note. 🤯

Instead of rolling back the fix for #48 whilst I figure this out, I'm going to let this bug stay active since it's the lesser of two. Sorry for the delays I'm struggling with this one 😅

claremacrae commented 2 years ago

Thanks for the update - much appreciated.

claremacrae commented 2 years ago

Just had a thought. Are you on the Obsidian Discord?

I’m guessing other plugin authors may have been tripped up by this, and so whether it would be worth your describing the issue in the plugin-dev channel there?

Aidurber commented 2 years ago

@claremacrae Yes, I did ask about it and it was suggested to create a code mirror plugin instead. However I'm going to see if I can find a solution that doesn't require me to rewrite this plugin.

claremacrae commented 2 years ago

Understood - thanks.

claremacrae commented 2 years ago

Just to note that on iOS it’s not just other open notes that affect the TOC contents. When Obsidian launches, the TOC blocks flash repeatedly, seemingly as each note in the vault is cached.

claremacrae commented 2 years ago

Or maybe it’s as each note with a TOC a block is read?

tprotopopescu commented 2 years ago

Thanks for the update! In a way, this is kind of a handy bug, since I get an automatic outline of whatever note I'm working on, assuming there is a note with a toc visible :)

ghost commented 2 years ago

Hello,

If I may suggest an approach :

As mentionned by @tprotopopescu , it can become a handy bug, so instead of fullty getting rid of it (which requires rewriting the plugin so far), you can :

So we will get something like this:

style: bullet
...
pinned: True | False
source: myNote.md
PiousAeneas commented 2 years ago

I like the idea of an option to pin the table (maybe make it a feature request?), though I wonder if leaving this bug as the default (as implied by having a second “source” option) might make the plug-in more confusing since my sense is that the expected functionality is that the TOC in a note will be the TOC for that note.