I had the idea of making the filter operator examples on tiddlywiki.com into a “live” playground. All the examples already have a “Try It” button which executes the filter example and toggles the button text to “Hide”. I thought it would be convenient to change the filter text into an edit-text widget after the “Try It” button is clicked. That way the filter examples can be changed on-the-fly.
I implemented my idea (see the attached $ _editions_tw5.com_operator-macros.json (2.0 KB) tiddler). Download the attachment and drop it onto https://tiddlywiki.com/#:[tag[Operator%20Examples]]) and import it. Then click the “Try It” in any of the filter examples.
I’m thinking of making a pull request and decided to seek some feedback here first.
Some notes:
- Every time “Try it”/“Hide” is toggled, the edit-text is replaced by the original filter text. So any user modifications are lost.
- Ctrl-z inside the edit-text doesn’t undo typing changes. I haven’t yet tried to figure out why. Ctrl-z in the Advanced search text boxes works fine for undo.
Here are the changes I made to the macro:
diff --git a/editions/tw5.com/tiddlers/system/operator-macros.tid b/editions/tw5.com/tiddlers/system/operator-macros.tid
index df917402b..2fc4e1952 100644
--- a/editions/tw5.com/tiddlers/system/operator-macros.tid
+++ b/editions/tw5.com/tiddlers/system/operator-macros.tid
@@ -7,23 +7,29 @@ tags: $:/tags/Macro
\define .operator-example(n,eg,ie)
<div class="doc-example">
-`$eg$`
-<$macrocall $name=".if" cond="""$ie$""" then="""<dd>→ $ie$</dd>"""/>
<$list filter="[title<.state-prefix>addsuffix{!!title}addsuffix[/]addsuffix[$n$]]" variable=".state">
<$reveal state=<<.state>> type="nomatch" text="show">
+ `$eg$`
+ <$macrocall $name=".if" cond="""$ie$""" then="""<dd>→ $ie$</dd>"""/>
<dl>
- <dd><$button set=<<.state>> setTo="show">Try it</$button></dd>
+ <dd><$button actions="""<$action-setfield $tiddler=<<.state>> text="show" filter=<<__eg__>>/>
+""">Try it</$button></dd>
</dl>
</$reveal>
<$reveal state=<<.state>> type="match" text="show">
+ <div class="tc-search tc-advanced-search">
+ <$edit-text tiddler=<<.state>> field="filter" tag="input" type=search/>
+ </div>
<dl>
<dd><$button set=<<.state>> setTo="">Hide</$button></dd>
</dl>
+ <$list filter="[<.state>get[filter]]" variable=".filter">
<blockquote class="doc-example-result">
- <ul><$list filter="""$eg$""" emptyMessage="(empty)">
+ <ul><$list filter=<<.filter>> emptyMessage="(empty)">
<li><$link><$view field="title"/></$link></li>
</$list></ul>
</blockquote>
+ </$list>
</$reveal>
</$list>
\end
I just noticed there is a somewhat related discussion about the .operator-example
macro and its somewhat inconsistent use: