Using the keyboard modifier variable in actions

Folks,

I am wondering if any one can provide some guidance on the modifier variable in a collection of different usage forms. It will also through light on the issues with actions and when values are “evaluated” eg at button render or on click.

  • I suspect @EricShulman @pmario amongst others, already understand this deeply enough to answer easily.

I have used the modifier variable to detect keyboard modifier keys such as shift, alt and ctrl including normal a few times with success. Then all of a sudden, I started to find it fragile, basically not working for some reason that is not clear to me.

  • I started this Topic to create a Discourse wiki post once I have clarity on this, please help us understand this.
  • Somehow conceptually I though the modifier value was “plucked from the air” and the time the button is clicked. But this does not seem to be the case.

Consider the following

  • Imagine each list has some action widgets within it.
\define button-actions(content)
<$list filter="[<modifier>match[normal]]" variable=nul>

</$list>

<$list filter="[<modifier>match[ctrl]]" variable=nul>

</$list>

<$list filter="[<modifier>match[alt]]" variable=nul>

</$list>

<$list filter="[<modifier>match[shift]]" variable=nul>

</$list>
\end

Now there are a few ways we can call the button-actions from a button or other trigger, note the buttons are numbered for subsequent reference.

<$button actions=<<button-actions param>> >
button 1
</$button>
<$button actions="""<<button-actions param>>""">
button 2
</$button>
<$button>
<<button-body-actions>>
button 3
</$button>
<$button>
<$list filter="[<modifier>match[normal]]" variable=nul>

</$list>

<$list filter="[<modifier>match[ctrl]]" variable=nul>

</$list>

<$list filter="[<modifier>match[alt]]" variable=nul>

</$list>

<$list filter="[<modifier>match[shift]]" variable=nul>

</$list>
button 4
</$button>

  • There is another possibility and that is to embed the modifier conditional list inside the actions="""<$list...""" let us call this button 5

Your feedback greatly appreciated.

That’s the only way you should do it:

<$button actions=<<button-actions>> >
button 1
</$button>

I think the above is best practice and the other examples shouldn’t be used.

Edit: I did remove the param element from the <<button-actions>> macro parameter. …

I have to check but your nominated option is not working for me I belive in part because of the macro being set at button render time.

  • I now realise there are other issues even if the responce to the modifier variable is addressed

Calling button actions with the “actions” parameter is the only way, where the actions are evaluated at click-time. …

If the actions are inside the button widget, you will get problems.

If parameters for actions calls are needed, I think that’s the only option at the moment. … I personally never needed any parameters in button actions.

2 Likes

@EricShulman gave a great explanation on this topic here:

1 Like

I think even in erics post there is a little ambiguity in the difference between actions=<<macroname param>> and actions="""<<macroname param>>""".

Once clear I my mind I will edit and adapt this topic as a guide. As a result I am seaking a deep understanding of this problematic and oft fragile part of tiddlywiki.

I see a need to include the button messages in this as well.