1
0
mirror of https://github.com/Jermolene/TiddlyWiki5 synced 2024-11-27 03:57:21 +00:00

Fix for filterrunprefixes using $tw.wiki (#5202)

* Fixed runprefix 'and' to use widget wiki

* Made widget arg of filterTiddlers optional again

* Switched to passing {wiki: wiki} to prefixes
This commit is contained in:
Cameron Fischer 2020-12-05 11:12:40 -05:00 committed by GitHub
parent ae5d78b4dd
commit fbe5bb229a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 13 additions and 12 deletions

View File

@ -16,10 +16,10 @@ Equivalent to + filter run prefix.
/* /*
Export our filter prefix function Export our filter prefix function
*/ */
exports.and = function(operationSubFunction) { exports.and = function(operationSubFunction,options) {
return function(results,source,widget) { return function(results,source,widget) {
// This replaces all the elements of the array, but keeps the actual array so that references to it are preserved // This replaces all the elements of the array, but keeps the actual array so that references to it are preserved
source = $tw.wiki.makeTiddlerIterator(results); source = options.wiki.makeTiddlerIterator(results);
results.splice(0,results.length); results.splice(0,results.length);
$tw.utils.pushTop(results,operationSubFunction(source,widget)); $tw.utils.pushTop(results,operationSubFunction(source,widget));
}; };

View File

@ -12,13 +12,13 @@ module-type: filterrunprefix
/* /*
Export our filter prefix function Export our filter prefix function
*/ */
exports.reduce = function(operationSubFunction) { exports.reduce = function(operationSubFunction,options) {
return function(results,source,widget) { return function(results,source,widget) {
if(results.length > 0) { if(results.length > 0) {
var accumulator = ""; var accumulator = "";
for(var index=0; index<results.length; index++) { for(var index=0; index<results.length; index++) {
var title = results[index], var title = results[index],
list = operationSubFunction($tw.wiki.makeTiddlerIterator([title]),{ list = operationSubFunction(options.wiki.makeTiddlerIterator([title]),{
getVariable: function(name) { getVariable: function(name) {
switch(name) { switch(name) {
case "currentTiddler": case "currentTiddler":
@ -46,4 +46,4 @@ exports.reduce = function(operationSubFunction) {
} }
}; };
})(); })();

View File

@ -280,20 +280,21 @@ exports.compileFilter = function(filterString) {
var filterRunPrefixes = self.getFilterRunPrefixes(); var filterRunPrefixes = self.getFilterRunPrefixes();
// Wrap the operator functions in a wrapper function that depends on the prefix // Wrap the operator functions in a wrapper function that depends on the prefix
operationFunctions.push((function() { operationFunctions.push((function() {
var options = {wiki: self};
switch(operation.prefix || "") { switch(operation.prefix || "") {
case "": // No prefix means that the operation is unioned into the result case "": // No prefix means that the operation is unioned into the result
return filterRunPrefixes["or"](operationSubFunction); return filterRunPrefixes["or"](operationSubFunction, options);
case "=": // The results of the operation are pushed into the result without deduplication case "=": // The results of the operation are pushed into the result without deduplication
return filterRunPrefixes["all"](operationSubFunction); return filterRunPrefixes["all"](operationSubFunction, options);
case "-": // The results of this operation are removed from the main result case "-": // The results of this operation are removed from the main result
return filterRunPrefixes["except"](operationSubFunction); return filterRunPrefixes["except"](operationSubFunction, options);
case "+": // This operation is applied to the main results so far case "+": // This operation is applied to the main results so far
return filterRunPrefixes["and"](operationSubFunction); return filterRunPrefixes["and"](operationSubFunction, options);
case "~": // This operation is unioned into the result only if the main result so far is empty case "~": // This operation is unioned into the result only if the main result so far is empty
return filterRunPrefixes["else"](operationSubFunction); return filterRunPrefixes["else"](operationSubFunction, options);
default: default:
if(operation.namedPrefix && filterRunPrefixes[operation.namedPrefix]) { if(operation.namedPrefix && filterRunPrefixes[operation.namedPrefix]) {
return filterRunPrefixes[operation.namedPrefix](operationSubFunction); return filterRunPrefixes[operation.namedPrefix](operationSubFunction, options);
} else { } else {
return function(results,source,widget) { return function(results,source,widget) {
results.splice(0,results.length); results.splice(0,results.length);

View File

@ -459,7 +459,7 @@ function runTests(wiki) {
it("should handle indirect operands", function() { it("should handle indirect operands", function() {
expect(wiki.filterTiddlers("[prefix{Tiddler8}] +[sort[title]]").join(",")).toBe("Tiddler Three,TiddlerOne"); expect(wiki.filterTiddlers("[prefix{Tiddler8}] +[sort[title]]").join(",")).toBe("Tiddler Three,TiddlerOne");
expect(wiki.filterTiddlers("[modifier{Tiddler8!!test-field}] +[sort[title]]").join(",")).toBe("TiddlerOne"); expect(wiki.filterTiddlers("[modifier{Tiddler8!!test-field}] +[sort[title]]").join(",")).toBe("TiddlerOne");
var fakeWidget = {getVariable: function() {return "Tiddler Three";}}; var fakeWidget = {wiki: wiki, getVariable: function() {return "Tiddler Three";}};
expect(wiki.filterTiddlers("[modifier{!!modifier}] +[sort[title]]",fakeWidget).join(",")).toBe("$:/TiddlerTwo,a fourth tiddler,one,Tiddler Three"); expect(wiki.filterTiddlers("[modifier{!!modifier}] +[sort[title]]",fakeWidget).join(",")).toBe("$:/TiddlerTwo,a fourth tiddler,one,Tiddler Three");
}); });