So far I haven’t encountered such a thing, but it would be SUPER helpful if when I do a search, and open a tiddler, my TOC (I’m using the standard TOC macros – toc-selective-expandable
I use the TOC extensively and often when I search for a topic, it’s difficult to track it down in the TOC (If it happens to be a ‘folder’ tiddler etc).
@EricShulman has a custom TOC on Inside TiddlyWiki that looks like the sort of thing you’re looking for. Try navigating through his guide and see how the drop-down TOC changes.
I’m not sure whether he’s documented it for general use, though. I took a quick look around https://tiddlytools.com/ and didn’t see it among the packages, although you can find some relevant tiddlers if you search for “TOC”.
to display a TOC that is very similar to the TWCore <<toc-selective-expandable roottagname>>, some very useful added features:
As @etardiff noted, TiddlyTools <<toc-tree>> includes handling for auto-opening branches that contain the current tiddler (as defined by the $:/HistoryList!!current-tiddler field contents).
TiddlyTools <<toc-tree>> also has handling for drag-and-drop re-organization of the tree items. Drag any tree item (or linked title in tiddler content) and drop it onto an existing tree item and it will be automatically inserted as a “child” of the tree item it was dropped on. If you hold the CTRL key when dropping, the dropped item will be added as a “sibling” BEFORE the item dropped upon. If you hold the SHIFT key when dropping, the dropped item will be added as a sibling AFTER the item dropped upon.
The <<toc-all>> macro shows the entire tree without the “selective expandable” handling
The <<toc-list>> macro outputs the entire tree as a “flat list” of tiddler titles. You can then use <$wikify name="tids" text="<<toc-list roottagname>>">
to capture this list for further processing (see InsideTiddlyWiki TiddlyTools/NavBar/Bottom for an example of previous/next navigation links)
The main problem with most TOCs is, that some tiddlers are tagged with several tags, that may be part of different branches in the TOC-tree. So it may be the “wrong” branch that is auto-selected. …
I did rewrite the TOC macros. They should contain enough information to allow auto-selecting and expanding. .. But I did not reliably resolve the problem described above.
As a workaround you can try my trails-plugin to see the “context” a tiddler is in. eg: Trails-Plugin imported to tw-com looks like this.
This works BEAUTIFULLY!
I used my existing TOC - with expand/collapse buttons, and just updated the macro call to toc-tree and BOOM! It worked, with all of your added features. Thank you SO much!
One tweak I wonder if you can help me with - if the selected node in the tree is a folder, and it is clicked, is there a tweak I can make to your macro that deselects it and collapses it? So far I don’t see a way to deselect/collapse the currently selected node.
The effect will be that when the “selected node in the tree” (i.e., the $:HistoryList!!current-tiddler) is a “folder” (i.e., has children), then it will no longer automatically open the branch to show it’s children, but it will still automatically open a branch if the selected node IS one of that branch’s descendents. Of course, you can always manually open a folder branch by using the “>” button next to that folder name.
Thank you for taking the time to offer a suggestion!
When I tried that my ‘folders’ quit opening at all hehe.
I’ll continue working on learning TW coding etc, and may try experimenting.
I love this epanded TOC macro. Thanks again for letting me know about it!
Sorry - by ‘folder’ I mean a parent within the TOC. I like to keep my TOC collapsed when I’m not digging through it (I’m weird), and the ONLY issue I have with the TiddlyTools/TOC is once a ‘folder’ is selected, it won’t collapse, unless I click on a different ‘folder’, but then that one won’t collapse.
That’s not true lol - sometimes I can click on a ‘folder’ label, then click the arrow next to it and it will collapse, but not always.
BUT - Having a TOC that shows me where my current tiddler is within the TOC is absolutely amazing!
The reason for this inconsistency is that the ToC path to the most recently opened tiddler insists on staying open.
If you open a tiddler that has no place in the ToC, then there won’t be a “foot in the door” preventing the collapse of the ToC. (And that’s probably the situation where you noticed what looked like inconsistent behavior.)
In theory, you could modify the chevron close-button action in the TiddlyTools/TOC so that it first clears the $:/HistoryList tiddler (or adds a dummy value at the top) before attempting to close that branch.
And I THINK I see where the branch item is being toggled:
\define toc-show-if-parent(here,exclude)
<!-- AUTO SHOW BRANCH IF IT CONTAINS CURRENT TIDDLER -->
<$list filter="[<__here__>!match<item>]" emptyMessage="<<toc-show-branch>>">
<$list filter="""[[$here$]get<field>enlist-input[]] -[subfilter<__exclude__>] -[[$here$]]""">
<$macrocall $name="toc-show-if-parent" here=<<currentTiddler>> exclude="""$exclude$ [[$here$]]"""/>
</$list>
</$list>
\end
\define toc-toggle-branch()
\whitespace trim
<span class="tt-toc-toggle" style="display:inline-block;width:1.2em;">
<$list filter=<<toc-item-is-branch>> emptyMessage=" ">
<$reveal state=<<toc-branch-is-open>> type="match" text="open">
<$button class="tc-btn-invisible" tooltip="collapse this item"> {{$:/core/images/down-arrow}}
<$action-setfield $tiddler=<<toc-config>> $index="""$(path)$/$(item)$"""/>
</$button>
</$reveal>
<$reveal state=<<toc-branch-is-open>> type="nomatch" text="open">
<$button class="tc-btn-invisible" tooltip="expand this item"> {{$:/core/images/right-arrow}}
<$action-setfield $tiddler=<<toc-config>> $index="""$(path)$/$(item)$""" $value="open"/>
</$button>
</$reveal>
</$list>
</span>
\end
There are a lot of cool features in there (Expand all/Collapse all, Drag and Drop etc) that make it tough to identify JUST the folder toggle. I’ve tried tweaking things here and there, to see what would happen - It breaks lol
I would like to maybe just have a toggle that says if you’re collapsing a folder, by clicking on the arrow, just ignore the current history - expand the branch stuff. Otherwise, do what it currently does.
To prevent the folder from expanding when it is the current tiddler, you need to change the emptyMessage logic in toc-show-if-parent() as I have already explained in my previous post. So… change this:
\define toc-show-if-parent(here,exclude)
<!-- AUTO SHOW BRANCH IF IT CONTAINS CURRENT TIDDLER -->
<$list filter="[<__here__>!match<item>]" emptyMessage="<<toc-show-branch>>">
<$list filter="""[[$here$]get<field>enlist-input[]] -[subfilter<__exclude__>] -[[$here$]]""">
<$macrocall $name="toc-show-if-parent" here=<<currentTiddler>> exclude="""$exclude$ [[$here$]]"""/>
</$list>
</$list>
\end
to this:
\define toc-show-if-parent(here,exclude)
<!-- AUTO SHOW BRANCH IF IT CONTAINS CURRENT TIDDLER -->
<$list filter="[<__here__>!match<item>]"
emptyMessage="<$list filter='[{$:/HistoryList!!current-tiddler}!match<item>]'><<toc-show-branch>></$list>">
<$list filter="""[[$here$]get<field>enlist-input[]] -[subfilter<__exclude__>] -[[$here$]]""">
<$macrocall $name="toc-show-if-parent" here=<<currentTiddler>> exclude="""$exclude$ [[$here$]]"""/>
</$list>
</$list>
\end
Note: I have done quite a lot of “code cleanup” and small fixes to TiddlyTools/TOC. I strongly suggest getting the latest update from https://tiddlytools.com/#TiddlyTools%2FTOC, which already includes the above change that enables the “folder toggle” handling that you want.
Thank you for re-explaining this. I think I had tried your earlier update, but missed where you explained clicking the folder itself (vs the arrow) would collapse it. So I had moved on to trying other stuff.
Sorry about that.
I’ve grabbed your latest and will use that.
Thanks again for the explanation!