From 4cca77b72d18ac39f78a757eee1ec803418c5eb9 Mon Sep 17 00:00:00 2001 From: etardiff <153414521+etardiff@users.noreply.github.com> Date: Wed, 28 Feb 2024 06:32:48 -0500 Subject: [PATCH] Rewrite tag-picker macros as procedures (#7883) This PR attempts to modernize the tag-picker macros as procedures, as @Jermolene suggested in [#7548 (comment)](https://github.com/Jermolene/TiddlyWiki5/pull/7548#issuecomment-1825458523). What I changed: * rewrote macros as procedures/replaced text substitutions with variables * replaced nested $set and $var widgets with $let widgets/functions * minor rewrites to reduce redundant code * some additional linebreaks for clarity *This is functionally identical to my initial PR, [#7880](https://github.com/Jermolene/TiddlyWiki5/pull/7880)*, minus the extra file I'd accidentally added. Thank you for bearing with me as I learn to navigate GitHub. --- core/wiki/macros/tag-picker.tid | 274 +++++++++++++++----------------- 1 file changed, 132 insertions(+), 142 deletions(-) diff --git a/core/wiki/macros/tag-picker.tid b/core/wiki/macros/tag-picker.tid index ede53ec2681..1eb5cb683f9 100644 --- a/core/wiki/macros/tag-picker.tid +++ b/core/wiki/macros/tag-picker.tid @@ -1,32 +1,33 @@ title: $:/core/macros/tag-picker -tags: $:/tags/Macro +tags: $:/tags/Global first-search-filter: [tags[]!is[system]search:titlesort[]] second-search-filter: [tags[]is[system]search:titlesort[]] -\define get-tagpicker-focus-selector() [data-tiddler-title="$(currentTiddlerCSSEscaped)$"] .tc-add-tag-name input +\procedure get-tagpicker-focus-selector() +\function currentTiddlerCSSEscaped() [escapecss[]] +[data-tiddler-title=`$(currentTiddlerCSSEscaped)$`] .tc-add-tag-name input +\end -\define delete-tag-state-tiddlers() <$action-deletetiddler $filter="[] [] []"/> +\procedure delete-tag-state-tiddlers() <$action-deletetiddler $filter="[] [] []"/> -\define add-tag-actions(actions,tagField:"tags") +\procedure add-tag-actions() \whitespace trim -<$set name="tag" value={{{ [<__tiddler__>get[text]] }}}> - <$list - filter="[!contains:$tagField$!match[]]" - variable="ignore" - emptyMessage="<$action-listops $tiddler=<> $field=<<__tagField__>> $subfilter='-[]'/>" - > - <$action-listops $tiddler=<> $field=<<__tagField__>> $subfilter="[trim[]]"/> - <$transclude $variable="__actions__"/> - - +<$let tag=<>> +<$action-listops $tiddler=<> $field=<> $subfilter='+[toggletrim[]]'/> +<$list + filter="[] :intersection[getenlist-input[]]" + variable="ignore" + emptyMessage="<>" +/> + <> <$action-setfield $tiddler=<> text="yes"/> \end -\define clear-tags-actions-inner() +\procedure clear-tags-actions-inner() \whitespace trim <$list - filter="[has[text]] [has[text]]" + filter="[has[text]] ~[has[text]]" variable="ignore" emptyMessage="<>" > @@ -34,144 +35,133 @@ second-search-filter: [tags[]is[system]search:titlesort[]] \end -\define clear-tags-actions() +\procedure clear-tags-actions() +\whitespace trim +<$let userInput=<>> + <$list + filter="[get[text]!match]" + emptyMessage="<>" + > + <$action-setfield $tiddler=<> text=<>/> + <$action-setfield $tiddler=<> text="yes"/> + + +\end + +\procedure add-button-actions() +<$action-listops $tiddler=<> $field=<> $subfilter="[trim[]]"/> +<> +<> +<$action-sendmessage $message="tm-focus-selector" $param=<>/> +\end + +\procedure list-tags(filter, suffix) \whitespace trim -<$set name="userInput" value={{{ [get[text]] }}}> - <$list filter="[get[text]!match]" emptyMessage="<>"> - <$action-setfield $tiddler=<> text=<>/><$action-setfield $tiddler=<> text="yes"/> +<$list + filter="[minlength{$:/config/Tags/MinLength}limit[1]]" + emptyMessage="
{{$:/language/Search/Search/TooShort}}
" variable="listItem" +> + <$list filter=<> variable="tag"> + <$let + button-classes=`tc-btn-invisible ${ [addsuffix] -[get[text]] :then[[]] ~tc-tag-button-selected }$` + currentTiddler=<> + > + {{||$:/core/ui/TagPickerTagTemplate}} + - + \end -\define tag-picker-inner(actions,tagField:"tags") +\procedure tag-picker-inner() \whitespace trim -<$vars +<$let newTagNameInputTiddlerQualified=<> newTagNameSelectionTiddlerQualified=<> - fallbackTarget={{$(palette)$##tag-background}} - colourA={{$(palette)$##foreground}} - colourB={{$(palette)$##background}} + fallbackTarget={{{ [getindex[tag-background]] }}} + colourA={{{ [getindex[foreground]] }}} + colourB={{{ [getindex[background]] }}} + + storeTitle={{{ [!match[]] ~[] }}} + tagSelectionState={{{ [!match[]] ~[] }}} + tagAutoComplete=<> + + refreshTitle=<> + nonSystemTagsFilter="[tags[]!is[system]search:titlesort[]]" + systemTagsFilter="[tags[]is[system]search:titlesort[]]" > - <$vars - storeTitle={{{ [!match[]] ~[] }}} - tagSelectionState={{{ [!match[]] ~[] }}} - > - <$vars - refreshTitle=<> - nonSystemTagsFilter="[tags[]!is[system]search:titlesort[]]" - systemTagsFilter="[tags[]is[system]search:titlesort[]]" - > -
-
- - <$macrocall - $name="keyboard-driven-input" - tiddler=<> - storeTitle=<> - refreshTitle=<> - selectionStateTitle=<> - inputAcceptActions="<$macrocall $name='add-tag-actions' actions=<<__actions__>> tagField=<<__tagField__>>/>" - inputCancelActions=<> - tag="input" - placeholder={{$:/language/EditTemplate/Tags/Add/Placeholder}} - focusPopup=<> - class="tc-edit-texteditor tc-popup-handle" - tabindex=<> - focus={{{ [{$:/config/AutoFocus}match[tags]then[true]] ~[[false]] }}} - filterMinLength={{$:/config/Tags/MinLength}} - cancelPopups=<> - configTiddlerFilter="[[$:/core/macros/tag-picker]]" - /> - - <$button popup=<> - class="tc-btn-invisible tc-btn-dropdown" - tooltip={{$:/language/EditTemplate/Tags/Dropdown/Hint}} - aria-label={{$:/language/EditTemplate/Tags/Dropdown/Caption}} +
+
+ + <$transclude + $variable="keyboard-driven-input" + tiddler=<> + storeTitle=<> + refreshTitle=<> + selectionStateTitle=<> + inputAcceptActions=<> + inputCancelActions=<> + tag="input" + placeholder={{$:/language/EditTemplate/Tags/Add/Placeholder}} + focusPopup=<> + class="tc-edit-texteditor tc-popup-handle" + tabindex=<> + focus={{{ [{$:/config/AutoFocus}match[tags]then[true]] ~[[false]] }}} + filterMinLength={{$:/config/Tags/MinLength}} + cancelPopups=<> + configTiddlerFilter="[[$:/core/macros/tag-picker]]" + /> + + <$button popup=<> + class="tc-btn-invisible tc-btn-dropdown" + tooltip={{$:/language/EditTemplate/Tags/Dropdown/Hint}} + aria-label={{$:/language/EditTemplate/Tags/Dropdown/Caption}} + > + {{$:/core/images/down-arrow}} + + <$reveal state=<> type="nomatch" text=""> + <$button actions=<> + class="tc-btn-invisible tc-small-gap tc-btn-dropdown" + tooltip={{$:/language/EditTemplate/Tags/ClearInput/Hint}} + aria-label={{$:/language/EditTemplate/Tags/ClearInput/Caption}} + > + {{$:/core/images/close-button}} + + + + <$let tag=<>> + <$button set=<> setTo="" + actions=<> > - {{$:/core/images/down-arrow}} + {{$:/language/EditTemplate/Tags/Add/Button}} - <$reveal state=<> type="nomatch" text=""> - <$button class="tc-btn-invisible tc-small-gap tc-btn-dropdown" - tooltip={{$:/language/EditTemplate/Tags/ClearInput/Hint}} - aria-label={{$:/language/EditTemplate/Tags/ClearInput/Caption}} - > - {{$:/core/images/close-button}}<> - - - - <$set name="tag" value={{{ [get[text]] }}}> - <$button set=<> setTo="" class=""> - <$action-listops $tiddler=<> $field=<<__tagField__>> $subfilter="[trim[]]"/> - <$transclude $variable="__actions__"/> - <$set name="currentTiddlerCSSEscaped" value={{{ [escapecss[]] }}}> - <><$action-sendmessage $message="tm-focus-selector" $param=<>/> - - {{$:/language/EditTemplate/Tags/Add/Button}} - - - + + +
+
+ <$reveal state=<> type="nomatch" text=""> +
+ <$let userInput=<>> + <$transclude $variable="list-tags" filter=<> suffix="-primaryList" /> +
+ <$transclude $variable="list-tags" filter=<> suffix="-secondaryList" /> +
-
- <$reveal state=<> type="nomatch" text="" default=""> -
- <$set name="userInput" value={{{ [get[text]] }}}> - <$list - filter="[minlength{$:/config/Tags/MinLength}limit[1]]" - emptyMessage="
- {{$:/language/Search/Search/TooShort}}
" variable="listItem"> - <$list filter=<> variable="tag"> - <$list - filter="[addsuffix[-primaryList]] -[get[text]]" - emptyMessage="<$vars button-classes='tc-btn-invisible tc-tag-button-selected' actions=<<__actions__>> tagField=<<__tagField__>> currentTiddler=<>>{{||$:/core/ui/TagPickerTagTemplate}}" - > - <$vars button-classes="tc-btn-invisible" - actions=<<__actions__>> - tagField=<<__tagField__>> - currentTiddler=<> - > - {{||$:/core/ui/TagPickerTagTemplate}} - - - - -
- <$list filter="[minlength{$:/config/Tags/MinLength}limit[1]]" emptyMessage="
- {{$:/language/Search/Search/TooShort}}
" variable="listItem"> - <$list filter=<> variable="tag"> - <$list filter="[addsuffix[-secondaryList]] -[get[text]]" - emptyMessage="<$vars button-classes='tc-btn-invisible tc-tag-button-selected' actions=<<__actions__>> tagField=<<__tagField__>> currentTiddler=<>>{{||$:/core/ui/TagPickerTagTemplate}}" - > - <$vars button-classes="tc-btn-invisible" - actions=<<__actions__>> - tagField=<<__tagField__>> - currentTiddler=<> - > - {{||$:/core/ui/TagPickerTagTemplate}} - - - - - -
- -
-
- - - + +
+
+ \end -\define tag-picker(actions,tagField:"tags") +\procedure tag-picker(actions, tagField:"tags") +\function userInput() [get[text]] +\function tag() [get[text]] \whitespace trim -<$vars saveTiddler=<> palette={{$:/palette}}> - <$list - filter="[match[]]" - emptyMessage="<$macrocall $name='tag-picker-inner' actions=<<__actions__>> tagField=<<__tagField__>>/>" - > - <$set name="newTagNameTiddler" value=<>> - <$macrocall $name="tag-picker-inner" actions=<<__actions__>> tagField=<<__tagField__>>/> - - - +<$let + saveTiddler=<> + palette={{$:/palette}} + qualified=<> + newTagNameTiddler={{{ [!match[]] ~[] }}} +> + <$transclude $variable="tag-picker-inner" /> + \end