Fix refreshing of global variables

Global variables access within attributes will automatically trigger a refresh if the attribute text changes, but that wasn't happening for transclusions.
This commit is contained in:
jeremy@jermolene.com 2022-05-31 09:19:01 +01:00
parent 006ae6e759
commit 613f4af20f
3 changed files with 34 additions and 1 deletions

View File

@ -360,7 +360,7 @@ Selectively refreshes the widget if needed. Returns true if the widget or any of
*/
TranscludeWidget.prototype.refresh = function(changedTiddlers) {
var changedAttributes = this.computeAttributes();
if(($tw.utils.count(changedAttributes) > 0) || (changedTiddlers[this.transcludeTitle] && this.parserNeedsRefresh())) {
if(($tw.utils.count(changedAttributes) > 0) || (this.transcludeTitle && changedTiddlers[this.transcludeTitle] && this.parserNeedsRefresh()) || (this.transcludeVariable && changedTiddlers["$:/global/" + this.transcludeVariable])) {
this.refreshSelf();
return true;
} else {

View File

@ -0,0 +1,31 @@
title: Globals/Refresh
description: Refreshing global procedures in shadow variables
type: text/vnd.tiddlywiki-multiple
tags: [[$:/tags/wiki-test-spec]]
title: Output
\whitespace trim
<<this-is-one>>
|
<<this-is-one blah>>
+
title: $:/global/this-is-one
\whitespace trim
\procedure example()
ONE
\end
\parameters (foo:"nothing")
<<example>>-<$text text=<<foo>>/>
+
title: Actions
<$action-setfield $tiddler="$:/global/this-is-one" $value="Jackdaw"/>
+
title: ExpectedResult
<p>Jackdaw</p><p>|Jackdaw</p>

View File

@ -38,6 +38,8 @@ describe("Wiki-based tests", function() {
var widgetNode = createWidgetNode(parseText(text,wiki),wiki);
// Render the widget node to the DOM
var wrapper = renderWidgetNode(widgetNode);
// Clear changes queue
wiki.clearTiddlerEventQueue();
// Run the actions if provided
if(wiki.tiddlerExists("Actions")) {
widgetNode.invokeActionString(wiki.getTiddlerText("Actions"));