A question about the relationship between a ToC and the tiddlers it includes

I am a fan of tree data structures, thus I use the Table of Contents concept very often to organize tiddlers in my wikis. I am familiar with the pros and cons of trees, I also know about other schools of knowledge management, like the Zettelkasten one, where cards are loosely coupled via references - I’ve tried that approach as well, but trees just work better for me. Maybe it’s the nature of the data I’m recording (mostly computer related, technical).

The intro above being listed mostly for context, I like the ToC as a view from a bird’s eye of a subset of tiddlers - sometimes it provides refactoring hints, like the need to move a leaf or a whole branch to another place in the tree. Luckily, this is done easy by changing a tag and letting the Relink plugin handle the renames automagically.

My question is about the relationship in the opposite direction. If I have a tiddler open in the story river and I know it belongs to a ToC - I even have some custom code (based on ancestors third party filter) that shows me the location of the tiddler in the ToC. My problem is that to get there, I have to go to the tiddler containing the ToC and click a lot to open the nodes until I get to the tiddler. I have no idea how to approach the problem but would it be possible to automate this? I would like a custom button or something in each tiddler that would:

  1. Open the tiddler containing the ToC
  2. Auto-expand all the nodes until the tiddler in the ToC becomes visible
  3. Center the ToC on the screen so the tiddler where tge button was clicked is in the middle

I believe @EricShulman’s TiddlyTools TOC rewrite already handles auto-expand and auto-scroll, so you’d just need to add a button (perhaps as a $:/tags/ViewTemplate segment, so it appears everywhere) to set the state tiddlers responsible for opening the sidebar and setting it to the TOC tab, if necessary.

These state tiddlers may vary depending on your layout/tabs, but you can figure them out by pasting [is[system]!sort[modified]] into Advanced Search > Filter and then folding/unfolding the sidebar and switching between tabs to see what changes. On TW-com, this is the code you’d need to navigate to the Contents tab:

<$button>Open TOC
<$action-setfield $tiddler="$:/state/sidebar" text="yes" />
<$action-setfield $tiddler="$:/state/tab/sidebar--595412856" text="TableOfContents" />
</$button>

Usually the place in the TOC is determined by a tag on the tiddler. Just opening that tag shows you both the siblings and parent of your target tiddler so goes a long way to finding its position in the toc.

Howevever we could generate a toc which is all open and use a search for the title using the browsers find function.

We can however do more, using a range of methods but the above are “out of the box”. Some tackle this with breadcrumbs.

  • The reason it is not strait forward is each collapsed toc item has its own state, so to open multiple “folders” in the toc demands setting the open status to all folders above.

We could use one of the tree walking macros the kin filter or ascendants descendants operators to generate breadcrumbs or to find each folder and set the open status, but it still wont focus on the item.

  • For tag based TOC’s I may look at an option to list the path to the tiddler in the tag dropdown, as an addition to reimagine tags.
  • Even better may be a fully open TOC that allows drag and drop, I think I saw this elsewhere.