From d4a1fe4689557557f9bfc831b119ca4f70070c81 Mon Sep 17 00:00:00 2001 From: BurningTreeC Date: Sun, 13 Oct 2024 21:18:59 +0200 Subject: [PATCH] rework kb-driven-input macro to procedures + new syntax --- core/modules/startup/render.js | 1 + core/wiki/macros/keyboard-driven-input.tid | 152 ++++++++++++--------- 2 files changed, 92 insertions(+), 61 deletions(-) diff --git a/core/modules/startup/render.js b/core/modules/startup/render.js index 7206a51d0..6a215f5bd 100644 --- a/core/modules/startup/render.js +++ b/core/modules/startup/render.js @@ -109,6 +109,7 @@ exports.startup = function() { } timerId = setTimeout(throttledRefresh,timeout); $tw.utils.extend(deferredChanges,changes); + console.log("skip"); } else { $tw.utils.extend(deferredChanges,changes); refresh(); diff --git a/core/wiki/macros/keyboard-driven-input.tid b/core/wiki/macros/keyboard-driven-input.tid index 7983ea9f0..183480b55 100644 --- a/core/wiki/macros/keyboard-driven-input.tid +++ b/core/wiki/macros/keyboard-driven-input.tid @@ -1,105 +1,135 @@ title: $:/core/macros/keyboard-driven-input tags: $:/tags/Macro -\define change-input-tab(stateTitle,tag,beforeafter,defaultState,actions) +\procedure change-input-tab(stateTitle,tag,beforeafter,defaultState,actions) \whitespace trim -<$set name="tabsList" filter="[all[shadows+tiddlers]tag<__tag__>!has[draft.of]]"> +<$set name="tabsList" filter="[all[shadows+tiddlers]tag!has[draft.of]]"> <$let - currentState={{{ [<__stateTitle__>!is[missing]get[text]] ~[<__defaultState__>] }}} + currentState={{{ [!is[missing]get[text]] ~[] }}} firstTab={{{ [enlistnth[1]] }}} lastTab={{{ [enlistlast[]] }}} - nextTab={{{ [all[shadows+tiddlers]tag<__tag__>!has[draft.of]$beforeafter$] ~[[$beforeafter$]removeprefix[after]suffix[]addprefix] ~[[$beforeafter$]removeprefix[before]suffix[]addprefix] }}} + nextTab={{{ [all[shadows+tiddlers]tag!has[draft.of]$beforeafter$] ~[[$beforeafter$]removeprefix[after]suffix[]addprefix] ~[[$beforeafter$]removeprefix[before]suffix[]addprefix] }}} > - <$action-setfield $tiddler=<<__stateTitle__>> text=<>/> + <$action-setfield $tiddler=<> text=<>/> $actions$ \end -\define keyboard-input-actions() +\procedure keyboard-input-actions() \whitespace trim -<$list filter="[<__index__>match[]]"> - <$action-setfield $tiddler=<<__storeTitle__>> text={{{ [<__tiddler__>get<__field__>] }}}/> - -<$list filter="[<__index__>!match[]]"> - <$action-setfield $tiddler=<<__storeTitle__>> text={{{ [<__tiddler__>getindex<__index__>] }}}/> - +<%if [match[]] %> + <$action-setfield $tiddler=<> text={{{ [get] }}}/> +<% endif %> +<%if [!match[]] %> + <$action-setfield $tiddler=<> text={{{ [getindex] }}}/> +<% endif %> \end -\define input-next-actions-inner() +\procedure input-next-actions-inner() \whitespace trim -<$list filter="[minlength[1]]" variable="ignore"> - <$action-setfield $tiddler=<<__selectionStateTitle__>> text=<>/> - <$list filter="[<__index__>match[]]"> - <$action-setfield $tiddler=<<__tiddler__>> $field=<<__field__>> $value={{{ [] +[splitregexp[(?:.(?!-))+$]] }}}/> - - <$list filter="[<__index__>!match[]]"> - <$action-setfield $tiddler=<<__tiddler__>> $index=<<__index__>> $value={{{ [] +[splitregexp[(?:.(?!-))+$]] }}}/> - - <$action-setfield $tiddler=<<__refreshTitle__>> text="yes"/> - +<%if [minlength[1]] %> + <$action-setfield $tiddler=<> text=<>/> + <%if [match[]] %> + <$action-setfield $tiddler=<> $field=<> $value={{{ [] +[splitregexp[(?:.(?!-))+$]] }}}/> + <% endif %> + <%if [!match[]] %> + <$action-setfield $tiddler=<> $index=<> $value={{{ [] +[splitregexp[(?:.(?!-))+$]] }}}/> + <% endif %> + <$action-setfield $tiddler=<> text="yes"/> +<% endif %> \end -\define input-next-actions(afterOrBefore:"after",reverse:"") +\procedure input-next-actions-after() \whitespace trim -<$list - filter="[<__storeTitle__>get[text]minlength<__filterMinLength__>] [<__filterMinLength__>match[0]] +[limit[1]]" - variable="ignore" -> +<%if [get[text]minlength] [match[0]] %> <$let - userInput={{{ [<__storeTitle__>get[text]] }}} - selectedItem={{{ [<__selectionStateTitle__>get[text]] }}} - configTiddler={{{ [subfilter<__configTiddlerFilter__>] }}} - primaryListFilter={{{ [get<__firstSearchFilterField__>] }}} - secondaryListFilter={{{ [get<__secondSearchFilterField__>] }}} + userInput={{{ [get[text]] }}} + selectedItem={{{ [get[text]] }}} + configTiddler={{{ [subfilter] }}} + primaryListFilter={{{ [get] }}} + secondaryListFilter={{{ [get] }}} > <$set name="filteredList" filter="[subfilteraddsuffix[-primaryList]] =[subfilteraddsuffix[-secondaryList]]" > <$let - nextItem={{{ [enlist$afterOrBefore$] ~[enlist$reverse$nth[1]] }}} + nextItem={{{ [enlistafter] ~[enlistnth[1]] }}} firstItem={{{ [enlistnth[1]] }}} lastItem={{{ [enlistlast[]] }}} > - <$list filter="[match!match]" variable="ignore"> - <$set name="nextItem" value={{{ [[$afterOrBefore$]match[before]thenaddsuffix[-userInput]] ~[] }}}> - <> - - - <$list filter="[match!match]" variable="ignore"> - <$set name="nextItem" value={{{ [[$afterOrBefore$]match[after]thenaddsuffix[-userInput]] ~[] }}}> - <> - - - <$list filter="[matchmatch]" variable="ignore"> + <%if [match!match] %> + <> + <%elseif [match!match] %> <$set name="nextItem" value={{{ [addsuffix[-userInput]] }}}> <> - - <$list filter="[!match!match]" variable="ignore"> + <%elseif [matchmatch] %> + <$set name="nextItem" value={{{ [addsuffix[-userInput]] }}}> + <> + + <%elseif [!match!match] %> <> - + <% endif %> - +<% endif %> \end -\define keyboard-driven-input(tiddler,storeTitle,field:"text",index:"",tag:"input",type,focus:"",inputAcceptActions,inputAcceptVariantActions,inputCancelActions,placeholder:"",default:"",class,focusPopup,rows,minHeight,tabindex,size,autoHeight,filterMinLength:"0",refreshTitle,selectionStateTitle,cancelPopups:"",configTiddlerFilter,firstSearchFilterField:"first-search-filter",secondSearchFilterField:"second-search-filter") +\procedure input-next-actions-before() \whitespace trim -<$keyboard key="((input-accept))" actions=<<__inputAcceptActions__>>> -<$keyboard key="((input-accept-variant))" actions=<<__inputAcceptVariantActions__>>> -<$keyboard key="((input-up))" actions=<>> -<$keyboard key="((input-down))" actions=<>> -<$keyboard key="((input-cancel))" actions=<<__inputCancelActions__>>> +<%if [get[text]minlength] [match[0]] %> + <$let + userInput={{{ [get[text]] }}} + selectedItem={{{ [get[text]] }}} + configTiddler={{{ [subfilter] }}} + primaryListFilter={{{ [get] }}} + secondaryListFilter={{{ [get] }}} + > + <$set + name="filteredList" + filter="[subfilteraddsuffix[-primaryList]] =[subfilteraddsuffix[-secondaryList]]" + > + <$let + nextItem={{{ [enlistbefore] ~[enlistreverse[]nth[1]] }}} + firstItem={{{ [enlistnth[1]] }}} + lastItem={{{ [enlistlast[]] }}} + > + <%if [match!match] %> + <$set name="nextItem" value={{{ [addsuffix[-userInput]] }}}> + <> + + <%elseif [match!match] %> + <> + <%elseif [matchmatch] %> + <$set name="nextItem" value={{{ [addsuffix[-userInput]] }}}> + <> + + <%elseif [!match!match] %> + <> + <% endif %> + + + +<% endif %> +\end + +\procedure keyboard-driven-input(tiddler,storeTitle,field:"text",index:"",tag:"input",type,focus:"",inputAcceptActions,inputAcceptVariantActions,inputCancelActions,placeholder:"",default:"",class,focusPopup,rows,minHeight,tabindex,size,autoHeight,filterMinLength:"0",refreshTitle,selectionStateTitle,cancelPopups:"",configTiddlerFilter,firstSearchFilterField:"first-search-filter",secondSearchFilterField:"second-search-filter") +\whitespace trim +<$keyboard key="((input-accept))" actions=<>> +<$keyboard key="((input-accept-variant))" actions=<>> +<$keyboard key="((input-up))" actions=<>> +<$keyboard key="((input-down))" actions=<>> +<$keyboard key="((input-cancel))" actions=<>> <$edit-text - tiddler=<<__tiddler__>> field=<<__field__>> index=<<__index__>> - inputActions=<> tag=<<__tag__>> class=<<__class__>> - placeholder=<<__placeholder__>> default=<<__default__>> focusPopup=<<__focusPopup__>> - focus=<<__focus__>> type=<<__type__>> rows=<<__rows__>> minHeight=<<__minHeight__>> - tabindex=<<__tabindex__>> size=<<__size__>> autoHeight=<<__autoHeight__>> - refreshTitle=<<__refreshTitle__>> cancelPopups=<<__cancelPopups__>> + tiddler=<> field=<> index=<> + inputActions=<> tag=<> class=<> + placeholder=<> default=<> focusPopup=<> + focus=<> type=<> rows=<> minHeight=<> + tabindex=<> size=<> autoHeight=<> + refreshTitle=<> cancelPopups=<> />