The problem is that macros are NOT functions. They simply “return” their content for further processing, depending entirely upon the “calling context” to decide what to do.
When you reference a macro directly in wikitext, the macro’s content is inserted in place of the macro call, and then that content is automatically processed (“wikified”) by the TWCore parser to produce the output. This gives the impression that the macro itself is a “function” that produces a “return value”.
However, when used as the value of a widget parameter (i.e., in the $action-setfield in your code), the macro content does not get parsed, and is just passed to the widget “as-is”. Thus, in your code above, you are actually replacing the tiddler text with the code from the <<new-content>>
macro… and, since that code invokes a $list widget that replaces itself, it gets into an infinite recursion, which locks up and crashes.
Here’s a different approach that uses the “search-replace” filter operator to do what you want:
\define todo(txt)
<$button> $txt$
<$vars in="""<<todo "$txt$">>""" out="""$txt$ ✓""">
<$action-setfield text={{{ [all[current]get[text]search-replace<in>,<out>] }}}/>
</$vars>
</$button>
\end
Note that there’s no need to split/join the text, or to use a regexp pattern match. search-replace[...],[...]
simply finds a literal match of the first parameter, and replaces it with the second parameter. In this case, it finds the macro <<todo "...">>
and replaces it with the same text, followed by a UNICODE checkmark symbol (the ✓
).
Let me know how it goes…
enjoy,
-e