Tiddlywiki5: Issue: Modal windows and keyboard shortcuts

Created on 17 Mar 2020  路  2Comments  路  Source: Jermolene/TiddlyWiki5

Recently I have noted that opening a modal window using shortcut does not release the already opened one. In other words assume a model window can be opened using Alt+Ctrl+A press this shortcut combination several times and each time you have a new modal windows!

As an example open https://kookma.github.io/TW-Utility/

and press Ctl+Alt+A (tested on Windows 10) several times and note to the number of widows opened!

Normally it is expected TW realize the already opened modal!

Most helpful comment

Modals are designed to be nestable, that is a modal can open another modal, and you can have multiple modals open at the same time. Try the modal at https://tiddlywiki.com/#Modals

Since there can be more than one modal, the tm-modal message does not toggle the modal, it displays a new modal every time.

If you simply want to avoid allowing the keyboard combination to open your modal more than once, you can do something like this in the actions for your shortcut:

<$reveal type="match" state="$:/state/sq/Notation/modal" text="hide">
<$action-setfield $tiddler="$:/state/sq/Notation/modal" text="show"/>
<$action-sendmessage $message="tm-modal" $param="$:/sq/Notation/ModalWrapper"/>
</$reveal>

and then in the close button for your modal:
<$button message="tm-close-tiddler">Close<$action-setfield $tiddler="$:/state/sq/Notation/modal" text="hide"/>

In my particular use case I am also able to use the same keyboard shortcut to toggle the modal, though this will depend on whether or not your modal has focus.
I accomplish this by wrapping my modal content in a keyboard widget as follows:

<$keyboard  key="alt+L" actions="""<$action-setfield $tiddler="$:/state/sq/Notation/modal" text="hide"/><$action-sendmessage $message="tm-close-tiddler"/> """>
<$transclude tiddler="$:/sq/Notation/Notation" />
</$keyboard>

This keyboard shortcut sets the same state tiddler while also closing the modal via a tm-close-tiddler message.

All 2 comments

Modals are designed to be nestable, that is a modal can open another modal, and you can have multiple modals open at the same time. Try the modal at https://tiddlywiki.com/#Modals

Since there can be more than one modal, the tm-modal message does not toggle the modal, it displays a new modal every time.

If you simply want to avoid allowing the keyboard combination to open your modal more than once, you can do something like this in the actions for your shortcut:

<$reveal type="match" state="$:/state/sq/Notation/modal" text="hide">
<$action-setfield $tiddler="$:/state/sq/Notation/modal" text="show"/>
<$action-sendmessage $message="tm-modal" $param="$:/sq/Notation/ModalWrapper"/>
</$reveal>

and then in the close button for your modal:
<$button message="tm-close-tiddler">Close<$action-setfield $tiddler="$:/state/sq/Notation/modal" text="hide"/>

In my particular use case I am also able to use the same keyboard shortcut to toggle the modal, though this will depend on whether or not your modal has focus.
I accomplish this by wrapping my modal content in a keyboard widget as follows:

<$keyboard  key="alt+L" actions="""<$action-setfield $tiddler="$:/state/sq/Notation/modal" text="hide"/><$action-sendmessage $message="tm-close-tiddler"/> """>
<$transclude tiddler="$:/sq/Notation/Notation" />
</$keyboard>

This keyboard shortcut sets the same state tiddler while also closing the modal via a tm-close-tiddler message.

@saqimtiaz
Thank you for your complete explanation and solution provided.

Added to TW-Scripts

Was this page helpful?
0 / 5 - 0 ratings

Related issues

KendrickLamarck picture KendrickLamarck  路  4Comments

phenomenal11 picture phenomenal11  路  5Comments

rmunn picture rmunn  路  4Comments

joshuafontany picture joshuafontany  路  5Comments

TiddlyTweeter picture TiddlyTweeter  路  3Comments