1
0
mirror of https://github.com/Jermolene/TiddlyWiki5 synced 2024-11-23 10:07:19 +00:00

Fix [is[variable]] operator doesn't work for "fake" variables #6303 (#6996)

* Add tests for [is[variable]] and "faked" variables

See GH #6303

* Make is[variable] and variables[] operators resilient to fake widgets

Co-authored-by: jeremy@jermolene.com <jeremy@jermolene.com>
This commit is contained in:
Rob Hoelz 2022-10-18 11:08:04 -05:00 committed by GitHub
parent 7b408c7adf
commit 24dbf69180
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 38 additions and 5 deletions

View File

@ -19,13 +19,13 @@ exports.variable = function(source,prefix,options) {
var results = []; var results = [];
if(prefix === "!") { if(prefix === "!") {
source(function(tiddler,title) { source(function(tiddler,title) {
if(!(title in options.widget.variables)) { if(options.widget.getVariable(title) === undefined) {
results.push(title); results.push(title);
} }
}); });
} else { } else {
source(function(tiddler,title) { source(function(tiddler,title) {
if(title in options.widget.variables) { if(options.widget.getVariable(title) !== undefined) {
results.push(title); results.push(title);
} }
}); });

View File

@ -16,9 +16,15 @@ Filter operator for returning the names of the active variables
Export our filter function Export our filter function
*/ */
exports.variables = function(source,operator,options) { exports.variables = function(source,operator,options) {
var names = []; var names = [],
for(var variable in options.widget.variables) { widget = options.widget;
names.push(variable); while(widget && !widget.hasOwnProperty("variables")) {
widget = widget.parentWidget;
}
if(widget && widget.variables) {
for(var variable in widget.variables) {
names.push(variable);
}
} }
return names.sort(); return names.sort();
}; };

View File

@ -0,0 +1,27 @@
title: Filters/FakeVariables
description: Test for https://github.com/Jermolene/TiddlyWiki5/issues/6303
type: text/vnd.tiddlywiki-multiple
tags: [[$:/tags/wiki-test-spec]]
title: Output
\whitespace trim
<$list variable="var" filter="[[existing variable should have output]] :filter[[..currentTiddler]is[variable]]">
<p><<var>></p>
</$list>
<$list variable="var" filter="[[non-existing variable should not have output]] :filter[[nonExistingVariable]is[variable]]">
<p><<var>></p>
</$list>
<$list variable="var" filter="[[existing variable negated should not have output]] :filter[[..currentTiddler]!is[variable]]">
<p><<var>></p>
</$list>
<$list variable="var" filter="[[non-existing variable negated should have output]] :filter[[nonExistingVariable]!is[variable]]">
<p><<var>></p>
</$list>
+
title: ExpectedResult
<p><p>existing variable should have output</p></p><p></p><p></p><p><p>non-existing variable negated should have output</p></p>