Sequential actions

Hello all, I have my own search function and it’s a sidebar tab. I’m trying to hijack the ctrl-shift-f shortcut to

  1. Change to the tab
  2. Delete it’s contents
  3. Activate (focus) the edit-text

Here’s what I’m trying to do:

<$action-setfield $tiddler="$:/state/tab/sidebar--595412856" $value="$:/organizer/tabs/search"/>
<$action-setfield $tiddler="$:/temp/mysearch" $value=""/>
<$action-sendmessage $message="tm-focus-selector" $param=".edit-search"/>

It’s the focus piece that doesn’t work. If I do it again the focus works (after already on the right tab). So it’s not broken code, just not running sequentially? I thought the issue would be solved by modifying it per https://tiddlywiki.com/#ActionWidget%20Execution%20Modes using

\define tv-action-refresh-policy() always

… but it seems to be something else.

The issue you are encountering is one that frustrates me often but there isn’t always a good solution for. The input field that you want to focus does not yet exist at the time that the tm-focus-selector message is handled. What is needed in these kinds of situations is to delay some actions until after the refresh cycle has completed, and short of some custom widgets I have not found a generalized solution for this.

In this particular situation, might you be able to set the input field to auto capture focus? That would give it focus as soon as the containing tab is activated.

<$edit-text focus="yes"....

3 Likes

Good to know - thought there might be something like a “wait” widget or something to get around it.

Funnily enough, I thought I’d tried the focus="true" thing, but I just tried again to be sure and now it’s working! Thanks