Sequence of actions inverted in the user interface

Please see Highlight -- Find and highlight text - #12 by Jan for context.

Clicking the Highlight button is one user action too many. Its more convenient to combine the Open and Highlight actions and trigger both with just the Open button. The code would be as follows (penultimate line added):

\define open()
<$list filter="my filter here" variable="tiddler">
  <$action-navigate $to=<<tiddler>> $scroll="no"/>
</$list>
<$action-highlight text={{!!_search-text}}/>
\end
<$button actions=<<open>>>Open</$button>

This does not work as desired though. The invokeAction functions of the action-navigate and action-highlight widgets are called in the right sequence, but in the user interface the highlighting occurs before the tiddlers are opened. This makes the highlighting disappear almost immediately, since by design a change in the story river clears it.

As I don’t (yet) fully understand the details of the Refreshmechanism my knowledge of TiddlyWiki is insufficient to understand/diagnose why this is the case,

The code of action-highlight is on GitHub: Highlight — Find and highlight text, in the tiddler $:/plugins/anttt/highlight-action-highlight/action-highlight.js. One notable difference between the actions is that action-highlight dispatches its event with the EventTarget.dispatchEvent function as opposed to with TiddlyWiki’s Widget.prototype.dispatchEvent function. I am not sure though if this is the cause of the problem. Also as of yet I have not been able to make TiddlyWiki’s dispatchEvent in action-highlight be listened to by a TiddlyWiki listener in the Highlight widget …

TiddlyWiki’s dispatchEvent function and listeners don’t solve the problem, as expected. The problem is the sequence of the relevant function calls:

  1. action-navigate.dispatchEvent (in invokeAction)
  2. action-highlight.dispatchEvent (in invokeAction)
  3. event listener in highlight.js
  4. event listener in render.js, which calls refresh.

i.e., action-navigate brackets action-highlight while given the sequence of actions in the open macro I would expect it to be

  1. action-navigate.dispatchEvent (in invokeAction)
  2. event listener in render.js, which calls refresh.
  3. action-highlight.dispatchEvent (in invokeAction)
  4. event listener in highlight.js

or

  1. action-navigate.dispatchEvent (in invokeAction)
  2. action-highlight.dispatchEvent (in invokeAction)
  3. event listener in render.js, which calls refresh.
  4. event listener in highlight.js

Using setTimeout (a macrotask) does not help.

The user interface problem I’m trying to solve is a small increase of convenience, of which I’m no longer sure. The Open button without highlighting opens the tiddlers but does not scroll, as desired, while the Highlight button may scroll… Still I would like to know the cause of the above behavior, if alone to increase my knowledge of (a small part) of TiddlyWIki’s code.