From 613f4af20fa83f99593cd2465764bb8f6c642885 Mon Sep 17 00:00:00 2001 From: "jeremy@jermolene.com" Date: Tue, 31 May 2022 09:19:01 +0100 Subject: [PATCH] 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. --- core/modules/widgets/transclude.js | 2 +- .../tiddlers/tests/data/globals/Refresh.tid | 31 +++++++++++++++++++ .../jasmine/run-wiki-based-tests.js | 2 ++ 3 files changed, 34 insertions(+), 1 deletion(-) create mode 100644 editions/test/tiddlers/tests/data/globals/Refresh.tid diff --git a/core/modules/widgets/transclude.js b/core/modules/widgets/transclude.js index d98e6b7e4..3f6586ff4 100755 --- a/core/modules/widgets/transclude.js +++ b/core/modules/widgets/transclude.js @@ -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 { diff --git a/editions/test/tiddlers/tests/data/globals/Refresh.tid b/editions/test/tiddlers/tests/data/globals/Refresh.tid new file mode 100644 index 000000000..8f9e90b01 --- /dev/null +++ b/editions/test/tiddlers/tests/data/globals/Refresh.tid @@ -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 + +<> +| +<> ++ +title: $:/global/this-is-one + +\whitespace trim + +\procedure example() +ONE +\end + +\parameters (foo:"nothing") +<>-<$text text=<>/> ++ +title: Actions + +<$action-setfield $tiddler="$:/global/this-is-one" $value="Jackdaw"/> ++ +title: ExpectedResult + +

Jackdaw

|Jackdaw

\ No newline at end of file diff --git a/plugins/tiddlywiki/jasmine/run-wiki-based-tests.js b/plugins/tiddlywiki/jasmine/run-wiki-based-tests.js index 6f12aaf89..5f28db061 100644 --- a/plugins/tiddlywiki/jasmine/run-wiki-based-tests.js +++ b/plugins/tiddlywiki/jasmine/run-wiki-based-tests.js @@ -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"));