mirror of
https://github.com/Jermolene/TiddlyWiki5
synced 2024-12-27 18:40:28 +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:
parent
ae5d78b4dd
commit
fbe5bb229a
@ -16,10 +16,10 @@ Equivalent to + filter run prefix.
|
||||
/*
|
||||
Export our filter prefix function
|
||||
*/
|
||||
exports.and = function(operationSubFunction) {
|
||||
exports.and = function(operationSubFunction,options) {
|
||||
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
|
||||
source = $tw.wiki.makeTiddlerIterator(results);
|
||||
source = options.wiki.makeTiddlerIterator(results);
|
||||
results.splice(0,results.length);
|
||||
$tw.utils.pushTop(results,operationSubFunction(source,widget));
|
||||
};
|
||||
|
@ -12,13 +12,13 @@ module-type: filterrunprefix
|
||||
/*
|
||||
Export our filter prefix function
|
||||
*/
|
||||
exports.reduce = function(operationSubFunction) {
|
||||
exports.reduce = function(operationSubFunction,options) {
|
||||
return function(results,source,widget) {
|
||||
if(results.length > 0) {
|
||||
var accumulator = "";
|
||||
for(var index=0; index<results.length; index++) {
|
||||
var title = results[index],
|
||||
list = operationSubFunction($tw.wiki.makeTiddlerIterator([title]),{
|
||||
list = operationSubFunction(options.wiki.makeTiddlerIterator([title]),{
|
||||
getVariable: function(name) {
|
||||
switch(name) {
|
||||
case "currentTiddler":
|
||||
@ -46,4 +46,4 @@ exports.reduce = function(operationSubFunction) {
|
||||
}
|
||||
};
|
||||
|
||||
})();
|
||||
})();
|
||||
|
@ -280,20 +280,21 @@ exports.compileFilter = function(filterString) {
|
||||
var filterRunPrefixes = self.getFilterRunPrefixes();
|
||||
// Wrap the operator functions in a wrapper function that depends on the prefix
|
||||
operationFunctions.push((function() {
|
||||
var options = {wiki: self};
|
||||
switch(operation.prefix || "") {
|
||||
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
|
||||
return filterRunPrefixes["all"](operationSubFunction);
|
||||
return filterRunPrefixes["all"](operationSubFunction, options);
|
||||
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
|
||||
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
|
||||
return filterRunPrefixes["else"](operationSubFunction);
|
||||
return filterRunPrefixes["else"](operationSubFunction, options);
|
||||
default:
|
||||
if(operation.namedPrefix && filterRunPrefixes[operation.namedPrefix]) {
|
||||
return filterRunPrefixes[operation.namedPrefix](operationSubFunction);
|
||||
return filterRunPrefixes[operation.namedPrefix](operationSubFunction, options);
|
||||
} else {
|
||||
return function(results,source,widget) {
|
||||
results.splice(0,results.length);
|
||||
|
@ -459,7 +459,7 @@ function runTests(wiki) {
|
||||
it("should handle indirect operands", function() {
|
||||
expect(wiki.filterTiddlers("[prefix{Tiddler8}] +[sort[title]]").join(",")).toBe("Tiddler Three,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");
|
||||
});
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user