diff --git a/core/modules/filterrunprefixes/filter.js b/core/modules/filterrunprefixes/filter.js index 555f8981b..55bc25dd7 100644 --- a/core/modules/filterrunprefixes/filter.js +++ b/core/modules/filterrunprefixes/filter.js @@ -17,10 +17,21 @@ exports.filter = function(operationSubFunction,options) { return function(results,source,widget) { if(results.length > 0) { var resultsToRemove = []; - results.each(function(result) { - var filtered = operationSubFunction(options.wiki.makeTiddlerIterator([result]),widget); + results.each(function(title) { + var filtered = operationSubFunction(options.wiki.makeTiddlerIterator([title]),{ + getVariable: function(name) { + switch(name) { + case "currentTiddler": + return "" + title; + case "..currentTiddler": + return widget.getVariable("currentTiddler"); + default: + return widget.getVariable(name); + } + } + }); if(filtered.length === 0) { - resultsToRemove.push(result); + resultsToRemove.push(title); } }); results.remove(resultsToRemove); diff --git a/core/modules/filterrunprefixes/reduce.js b/core/modules/filterrunprefixes/reduce.js index 534c3e450..33ec25c7f 100644 --- a/core/modules/filterrunprefixes/reduce.js +++ b/core/modules/filterrunprefixes/reduce.js @@ -19,23 +19,25 @@ exports.reduce = function(operationSubFunction,options) { var index = 0; results.each(function(title) { var list = operationSubFunction(options.wiki.makeTiddlerIterator([title]),{ - getVariable: function(name) { - switch(name) { - case "currentTiddler": - return "" + title; - case "accumulator": - return "" + accumulator; - case "index": - return "" + index; - case "revIndex": - return "" + (results.length - 1 - index); - case "length": - return "" + results.length; - default: - return widget.getVariable(name); - } + getVariable: function(name) { + switch(name) { + case "currentTiddler": + return "" + title; + case "..currentTiddler": + return widget.getVariable("currentTiddler"); + case "accumulator": + return "" + accumulator; + case "index": + return "" + index; + case "revIndex": + return "" + (results.length - 1 - index); + case "length": + return "" + results.length; + default: + return widget.getVariable(name); } - }); + } + }); if(list.length > 0) { accumulator = "" + list[0]; } diff --git a/core/modules/filterrunprefixes/sort.js b/core/modules/filterrunprefixes/sort.js index 689193fff..ecaba9313 100644 --- a/core/modules/filterrunprefixes/sort.js +++ b/core/modules/filterrunprefixes/sort.js @@ -26,15 +26,17 @@ exports.sort = function(operationSubFunction,options) { compareFn; results.each(function(title) { var key = operationSubFunction(options.wiki.makeTiddlerIterator([title]),{ - getVariable: function(name) { - switch(name) { - case "currentTiddler": - return "" + title; - default: - return widget.getVariable(name); - } + getVariable: function(name) { + switch(name) { + case "currentTiddler": + return "" + title; + case "..currentTiddler": + return widget.getVariable("currentTiddler"); + default: + return widget.getVariable(name); } - }); + } + }); sortKeys.push(key[0] || ""); }); results.clear(); diff --git a/core/modules/filters/filter.js b/core/modules/filters/filter.js index 4be552cff..8284929a7 100644 --- a/core/modules/filters/filter.js +++ b/core/modules/filters/filter.js @@ -20,7 +20,18 @@ exports.filter = function(source,operator,options) { results = [], target = operator.prefix !== "!"; source(function(tiddler,title) { - var list = filterFn.call(options.wiki,options.wiki.makeTiddlerIterator([title]),options.widget); + var list = filterFn.call(options.wiki,options.wiki.makeTiddlerIterator([title]),{ + getVariable: function(name) { + switch(name) { + case "currentTiddler": + return "" + title; + case "..currentTiddler": + return options.widget.getVariable("currentTiddler"); + default: + return options.widget.getVariable(name); + } + } + }); if((list.length > 0) === target) { results.push(title); } diff --git a/core/modules/filters/reduce.js b/core/modules/filters/reduce.js index 206936887..831b354a1 100644 --- a/core/modules/filters/reduce.js +++ b/core/modules/filters/reduce.js @@ -31,6 +31,8 @@ exports.reduce = function(source,operator,options) { switch(name) { case "currentTiddler": return "" + title; + case "..currentTiddler": + return options.widget.getVariable("currentTiddler"); case "accumulator": return "" + accumulator; case "index": diff --git a/core/modules/filters/sortsub.js b/core/modules/filters/sortsub.js index f556bfafc..a926362e3 100644 --- a/core/modules/filters/sortsub.js +++ b/core/modules/filters/sortsub.js @@ -27,10 +27,13 @@ exports.sortsub = function(source,operator,options) { iterator(options.wiki.getTiddler(title),title); },{ getVariable: function(name) { - if(name === "currentTiddler") { - return title; - } else { - return options.widget.getVariable(name); + switch(name) { + case "currentTiddler": + return "" + title; + case "..currentTiddler": + return options.widget.getVariable("currentTiddler"); + default: + return options.widget.getVariable(name); } } }); diff --git a/editions/tw5.com/tiddlers/filters/filter.tid b/editions/tw5.com/tiddlers/filters/filter.tid index 62619c20f..bd6cae1b9 100644 --- a/editions/tw5.com/tiddlers/filters/filter.tid +++ b/editions/tw5.com/tiddlers/filters/filter.tid @@ -1,6 +1,6 @@ caption: filter created: 20200929174420821 -modified: 20201027185144953 +modified: 20210522162551921 op-input: a [[selection of titles|Title Selection]] passed as input to the filter op-neg-input: a [[selection of titles|Title Selection]] passed as input to the filter op-neg-output: those input titles that <<.em "do not">> pass the filter <<.place S>> @@ -28,6 +28,8 @@ Simple filter operations can be concatenated together directly (eg `[tag[HelloTh ``` +Note that within the subfilter, the "currentTiddler" variable is set to the title of the tiddler being processed. The value of currentTiddler outside the subfilter is available in the variable "..currentTiddler". <<.from-version "5.1.24">> + <<.tip "Compare with the similar [[subfilter|subfilter Operator]] operator which runs a subfilter and directly returns the results">> <<.tip "Compare with the analagous named filter run prefix `:filter`">> diff --git a/editions/tw5.com/tiddlers/filters/reduce.tid b/editions/tw5.com/tiddlers/filters/reduce.tid index d9893346c..d566dad59 100644 --- a/editions/tw5.com/tiddlers/filters/reduce.tid +++ b/editions/tw5.com/tiddlers/filters/reduce.tid @@ -1,6 +1,6 @@ caption: reduce created: 20201004154131193 -modified: 20201208185109549 +modified: 20210522162536854 op-input: a [[selection of titles|Title Selection]] passed as input to the filter op-output: the final result of running the subfilter <<.place S>> op-parameter: a [[filter expression|Filter Expression]]. Optional second parameter for initial value for accumulator @@ -18,6 +18,7 @@ The following variables are available within the subfilter: * ''accumulator'' - the result of the previous subfilter run * ''currentTiddler'' - the input title +* ''..currentTiddler'' - the value of the variable `currentTiddler` outside the subfilter. <<.from-version "5.1.24">> * ''index'' - the numeric index of the current list item (with zero being the first item in the list) * ''revIndex'' - the reverse numeric index of the current list item (with zero being the last item in the list) * ''length'' - the total length of the input list diff --git a/editions/tw5.com/tiddlers/filters/sortsub Operator.tid b/editions/tw5.com/tiddlers/filters/sortsub Operator.tid index 451b979c9..f010357f2 100644 --- a/editions/tw5.com/tiddlers/filters/sortsub Operator.tid +++ b/editions/tw5.com/tiddlers/filters/sortsub Operator.tid @@ -1,6 +1,6 @@ caption: sortsub created: 20200424160155182 -modified: 20210428152533501 +modified: 20210522162521222 op-input: a [[selection of titles|Title Selection]] op-neg-output: the input, sorted into reverse order by the result of evaluating subfilter <<.param S>> op-output: the input, sorted into ascending order by the result of evaluating subfilter <<.param S>> @@ -15,7 +15,9 @@ type: text/vnd.tiddlywiki Each item in the list of input titles is passed to the subfilter in turn. The subfilter transforms the input titles into the form needed for sorting. For example, the subfilter `[length[]]` transforms each input title in the number representing its length, and thus sorts the input titles according to their length. -Note that within the subfilter, the "currentTiddler" variable is set to the title of the tiddler being processed. This permits subfilters like `[{!!value}divide{!!cost}]` to be used for computation. +Note that within the subfilter, the "currentTiddler" variable is set to the title of the tiddler being processed. This permits subfilters like `[{!!value}divide{!!cost}]` to be used for computation. + +The value of currentTiddler outside the subfilter is available in the variable "..currentTiddler". <<.from-version "5.1.24">> The suffix <<.place T>> determines how the items are compared and can be: diff --git a/editions/tw5.com/tiddlers/filters/syntax/Filter Expression.tid b/editions/tw5.com/tiddlers/filters/syntax/Filter Expression.tid index ec72fbd6a..34c07faea 100644 --- a/editions/tw5.com/tiddlers/filters/syntax/Filter Expression.tid +++ b/editions/tw5.com/tiddlers/filters/syntax/Filter Expression.tid @@ -1,5 +1,5 @@ created: 20150124182421000 -modified: 20210428084144231 +modified: 20210522162642994 tags: [[Filter Syntax]] title: Filter Expression type: text/vnd.tiddlywiki @@ -33,6 +33,8 @@ If a run has: <<.tip "Compare named filter run prefix `:reduce` with [[reduce Operator]] which is used to used to flatten a list of items down to a single item by repeatedly applying a subfilter.">> +<<.tip """Within the filter runs prefixed with `:reduce`, `:sort` and `:filter`, the "currentTiddler" variable is set to the title of the tiddler being processed. The value of currentTiddler outside the subfilter is available in the variable "..currentTiddler".<<.from-version "5.1.24">>""" >> + In technical / logical terms: |!Run |!Equivalent named prefix |!Interpretation |!Output | diff --git a/editions/tw5.com/tiddlers/filters/syntax/Sort Filter Run Prefix.tid b/editions/tw5.com/tiddlers/filters/syntax/Sort Filter Run Prefix.tid index 2fca72716..aed26cb6b 100644 --- a/editions/tw5.com/tiddlers/filters/syntax/Sort Filter Run Prefix.tid +++ b/editions/tw5.com/tiddlers/filters/syntax/Sort Filter Run Prefix.tid @@ -1,5 +1,5 @@ created: 20210428083929749 -modified: 20210428140713422 +modified: 20210522162628946 tags: [[Filter Syntax]] [[Filter Run Prefix]] title: Sort Filter Run Prefix type: text/vnd.tiddlywiki @@ -13,7 +13,7 @@ type: text/vnd.tiddlywiki Each input title from previous runs is passed to this run in turn. The filter run transforms the input titles into the form needed for sorting. For example, the filter run `[length[]]` transforms each input title in to the number representing its length, and thus sorts the input titles according to their length. -Note that within the filter run, the "currentTiddler" variable is set to the title of the tiddler being processed. This permits filter runs like `:sort:number[{!!value}divide{!!cost}]` to be used for computation. +Note that within the filter run, the "currentTiddler" variable is set to the title of the tiddler being processed. This permits filter runs like `:sort:number[{!!value}divide{!!cost}]` to be used for computation. The value of currentTiddler outside the run is available in the variable "..currentTiddler". The `:sort` filter run prefix uses an extended syntax that allows for multiple suffixes, some of which are required: