Executing actions on navigation clicks

One use case where this does not work as a general solution for adding actions to navigation clicks is suppression of scrolling to the opened tiddler (by pressing Ctrl while clicking). The tm-navigate message passed on by the LinkCatcherWidget does not seem to contain all the information from the message intercepted by the widget.
And since tm-navigate unfortunately cannot (yet?) be meaningfully called from within wikitext / macros, it does not seem possible to work around this limitation without JavaScript.

Have a nice day
Yaisog

PS: I also tried the ActionNavigateWidget without success. Even setting $scroll="no" did not work as intended, which seems odd. The seemingly only way to make it work is to manually insert the clicked tiddler into the $:/StoryList without any navigation calls.

The $messagecatcher widget might be a better fit there:
https://tiddlywiki.com/#MessageCatcherWidget

1 Like

The appeal of the LinkCatcherWidget was that it has the message parameter to enable propagation in the way @btheado used it. I’ll try to get the MessageCatcherWidget to work next.

Have a nice day
Yaisog

Thanks @saqimtiaz, that worked! Didn’t even have to use $scroll in the good ol’ ActionNavigateWidget. Good to know that the LinkCatcherWidget is somewhat borked. I think I might revisit some troubles I had before with toc-tabbed-external-nav modifications I had made (catch links to other toc entries when clicked on in the content pane and reroute only these to selectedTiddler as if it was a click from the toc pane).

Have a nice day
Yaisog

$linkcatcher is now best thought of as a more accessible form of $messagecatcher with a narrow focus on intercepting the $tm-navigate message.

For more complex use cases $messagecatcher provides greater flexibility.

You could add unfold action to the close button or create a undold all?

So, turns out it doesn’t work 100%. If I click a link which is not in the StoryList yet, $action-navigate – since it is called from the $messagecatcher in the PageTemplate – seems to think that the navigation originated outside the story river and always appends the opened tiddler at the end. I configured such links to open below the originating tiddler.
So I tried to add this to the $messagecatcher actions

<$action-listops $tiddler=<<tv-story-list>> $subfilter="+[insertbefore:event-navigateFromTitle<event-navigateTo>move<event-navigateTo>]"/>

Now the new tiddler can open anywhere: at the correct position, one position too far down, or at the end. I guess it’s due to timing issues between the $action-navigate widget and the $action-listops widget, both operating on the same list.
I started to write a macro to replace the $action-navigate widget by messing directly with the StoryList and HistoryList, but now clicking on a link doesn’t go to the tiddler anymore (it does put the opened tiddler at the correct position in the StoryList, though). I think it might be because I can only edit the current-tiddler field of the HistoryList, but not the JSON history data from within a Wikitext macro.
Anyone have any good ideas?
Have a nice day
Yaisog

It would be helpful if you took a step back and described what you are trying to achieve, and shared a minimal test case that demonstrates the issue you are running into.

What are you trying to achieve?

  • Is it the aforementioned open the next tiddler below the current, and close all others?

I would advise not playing with the standard story mechanism an instead provide your own navigation method. This behaviour you ask for would perhaps be better being made available to a subset of tiddlers or from a custom sideBar tab, eg your custom contents, or on the current Tiddler.

If you know the tiddler you wish to navigate to you can use/read the the history list $:/HistoryList!!current-tiddler to get the current tiddler (last navigated to) , save this (in a variable), close all and open only the “currentTiddler” and the nominated tiddler.

Thanks for your patience so far, I really appreciate your help.
So, here’s what was trying to do and how I got there:
I set up a PageTemplate as described way above, with a $messagecatcher calling a macro on intercepting tm-navigate,

<$messagecatcher $tm-navigate=<<additional-link-actions>> >

The macro is this:

\define additional-link-actions()
<$action-log message="$messagecatcher in $:/mwi/ui/PageTemplate"
             from=<<event-navigateFromTitle>>
             to=<<event-navigateTo>>
             modifier=<<modifier>>
             list={{$:/StoryList!!list}} />
<$list filter="[<modifier>match[normal]]" variable="void" >
	<$action-setfield $tiddler="$:/state/tab/sidebar--595412856" text="$:/mwi/ui/SideBar/Meta" />
</$list>
<$action-navigate $to=<<event-navigateTo>> />
\end

When a tiddler is actually navigated to (not just added to the river by pressing Ctrl), I want the sidebar to switch to a tab containing additional information on the tiddler. This sidebar tab gets the information about which tiddler is shown from $:/HistoryList!!current-tiddler as @TW_Tones also suggested.
The mechanism basically works, but now newly opened tiddlers are always – no matter where the click originated – added to the end of the story (my setting for tiddlers opened from outside the river) instead of immediately after the navigateFromTitle tiddler (my setting for tiddlers opened from within the river). $action-navigate does not seem to pass on information about the click source. This can also be seen in the HistoryList which only contains the title of the target.
So I added this code:

<$list filter="[<event-navigateFromTitle>!is[blank]] [<tv-story-list>!contains<event-navigateTo>] +[nth[2]]" variable="void">
	<$action-listops $tiddler=<<tv-story-list>> $subfilter="+[insertbefore:event-navigateFromTitle<event-navigateTo>move<event-navigateTo>]"/>
</$list>

When there is a navigateFromTitle and the tiddler is not already in the story, it is added right after the source of the click. If the source is not in the story, the new tiddler is added at the end (logic of the insertbefore operator). I added the code before the call to $action-navigate so that the navigator widget would always find the target tiddler already present in the story.
Now, what I stumbled over yesterday, and found while typing everything up here, was a second $messagecatcher with a similar purpose I had set up in the ViewTemplate and forgot about. Their interaction shifted the location of the new tiddler erratically. After I disabled that, everything seems to work as expected now. All the while keeping the extra code very minimal. Oh joy of joys!
I have to requests for the core developers, though:

  1. Please enable us to call tm-navigate with the $action-sendmessage macro, to populate navigateFromTitle, etc. directly. Or alternatively, extend the $action-navigate to be able to pass on such information.
  2. Can someone explain to me how the browser navigation to a tiddler is done? Especially, how does the zoomin storyview know which tiddler to show, and how does it show that tiddler and hide the others?

Making me write this down was a great help. Thank you again!
Yaisog

3 Likes

I recommend creating a Github issue: https://github.com/jermolene/TiddlyWiki5

I think it could also be interesting to consider an option where $messagecatcher intercepts a message and executes actions accordingly, but allows the original message to propagate.

1 Like