Thanks! That worked for external nav. Much simpler than my solution. Having some time to consider it, I have decided to define these marcos locally since I only plan to use them in one tiddler. Thanks for pointing out that I could do that.
To make it work with internal nav, I had to edit the toc-tabbed-internal-nav
macro and add a new one that I called NavigateToIfMatchesTitle
.
\define NavigateToIfMatchesTitle()
<%if [<event-navigateTo>match{$:/temp/toc/selectedTiddler!!text}] %>
<$action-navigate $to=<<event-navigateTo>> />
<%else%>
<!-- Looks like there is not a way to propagate messages after they have been caught,
which is what needs to happen here. Instead, manually recreate the action.
https://github.com/TiddlyWiki/TiddlyWiki5/issues/6493
-->
<$action-setfield $tiddler=<<__selectedTiddler__>> text=<<event-navigateTo>> />
<%endif%>
\end
\define toc-tabbed-internal-nav(tag,sort:"",selectedTiddler:"$:/temp/toc/selectedTiddler",unselectedText,missingText,template:"",exclude)
\whitespace trim
<$let __tag__={{{ [<__tag__>is[blank]then<currentTiddler>else<__tag__>] }}}>
<!-- CHANGED: linkcatcher replaced with messagecatch and custom macro. -->
<$messagecatcher $tm-navigate=<<NavigateToIfMatchesTitle>> >
<$macrocall $name="toc-tabbed-external-nav" tag=<<__tag__>> sort=<<__sort__>> selectedTiddler=<<__selectedTiddler__>> unselectedText=<<__unselectedText__>> missingText=<<__missingText__>> template=<<__template__>> exclude=<<__exclude__>> />
</$messagecatcher>
</$let>
\end
Explanation:
The <<__selectedTiddler__>>:text
field holds the clicked link title. The view shows the contents of the tiddler that has that title.
So when a user clicks the link in the left navigation tree, the <<__selectedTiddler__>>:text
is updated to the new title, and the view updates to show the text of the tiddler with that title.
When a user clicks on a link within the view, the messagecatcher
uses NavigateToIfMatchesTitle
to check if that tiddler is already the one being viewed. If yes, then the tiddler will be opened separately. If the link is to a different tiddler, then it updates <<__selectedTiddler__>>:text
field. The view automatically updates.
Copy of @EricShulman’s solution for the sake of completeness:
\define toc-caption()
\whitespace trim
<span class="tc-toc-caption tc-tiny-gap-left">
<$link><$transclude field="caption"><$view field="title"/></$transclude></$link>
</span>
\end
Putting all of these macros together allows toc-tabbed-internal-nav
, but you can click on the title to follow that link and open the tiddler separately.