Open then scroll to anchor in tiddler

Folks,

I am working on a scroll to anchor within a tiddler and need to solve the following if possible;

Can I have a single click both open a tiddler and scroll to a position within that tiddler?

In the following code the button uses the actions parameter, it always navigates to the current tiddler including when it is not open. This a code snippet and does not work standalone;

\define scroll-to-actions(string time:"1000") 
<$action-navigate $to=<<currentTiddler>> $scroll=no/>
<$action-sendmessage $message="tm-scroll" selector="[anchor='$string$']" animationDuration="$time$"/>
\end
 <$button class="tc-btn-invisible tc-tiddlylink" tooltip="Click to scroll to this item" actions=<<scroll-to-actions """$text$""" """$time$""">> >
         $text$
  </$button>
  • If the current tiddler is open already it scrolls to the correct string.
  • If the current tiddler is NOT open already, it opens the correct tiddler, but must be clicked a second time to scroll to the correct string.

I have tried the actionNavigate in the button body and the scroll only in the button actions but that did not work any differently.

Is there a way to ensure the one (1) click causes BOTH actions to be performed one after the other?

Modifying the $scroll to yes

  • If scroll=yes it and the current tiddler is OPEN or NOT already, it opens the correct tiddler, but clicking will never scroll to the correct string.

Using the message on the button
<$button message="tm-navigate" navigateTo=<<currentTiddler>>
Does not open the tiddler

1 Like

I am building a solution now, but came accross an issue when trying to also get links to unopened tiddlers Open then scroll to anchor in tiddler

I have it working via an anchor and anchor-link macro, I built an automatic contents and will share soon.

That may not be possible.

“Opening a tiddler” means adding it to the $:/StoryList tiddler, but the tiddler will not actually be displayed until the next refresh cycle. That means that immediately after modifying the story list, the tiddler it won’t actually be open, and so it isn’t possible to scroll it an anchor within it.

To make things work we need to extend the navigation mechanism to include an anchor as well as a target tiddler title. That is something I’m working on as part of the wikitext navigator in https://twpub-tools.org.

Is there a way to cause a refresh cycle? An action to do so perhaps?

I can display a link to the unopened tiddler if it is not in the story list as a work around. So the user expects a two step process.

1 Like

No, that is not possible.

For those who are interested: Internally, the refresh cycle needs a chance to run every time any value in the store changes. But we don’t want to run the refresh cycle for every modification because it would give terrible performance for bulk operations. Instead, the refresh cycle runs as an asynchronous task, which defers it until all the outstanding tiddler modifications have finished. In effect, the TiddlyWiki core uses cooperative multitasking (ie non-preemptive) to manage two different threads that feed one another.

But as I say, there is perfectly good solution for this issue that works properly with TiddlyWiki’s architecture, so that’s probably the way to go.

2 posts were split to a new topic: Wikitext navigator and TWPub