From eb8f69dd038562adbc941b95a8125ff880010e6d Mon Sep 17 00:00:00 2001 From: Jeremy Ruston Date: Mon, 19 Jan 2026 12:52:58 +0000 Subject: [PATCH] =?UTF-8?q?Merge=20subfilter=20fix=20from=C2=A0#9595?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- core/modules/filters.js | 11 +++++++---- core/modules/filters/subfilter.js | 4 +++- 2 files changed, 10 insertions(+), 5 deletions(-) diff --git a/core/modules/filters.js b/core/modules/filters.js index 7c8cb21ba..57009afad 100644 --- a/core/modules/filters.js +++ b/core/modules/filters.js @@ -230,8 +230,8 @@ exports.getFilterRunPrefixes = function() { return this.filterRunPrefixes; } -exports.filterTiddlers = function(filterString,widget,source) { - var fn = this.compileFilter(filterString); +exports.filterTiddlers = function(filterString,widget,source,options) { + var fn = this.compileFilter(filterString,options); try { const fnResult = fn.call(this,source,widget); return fnResult; @@ -244,8 +244,11 @@ exports.filterTiddlers = function(filterString,widget,source) { Compile a filter into a function with the signature fn(source,widget) where: source: an iterator function for the source tiddlers, called source(iterator), where iterator is called as iterator(tiddler,title) widget: an optional widget node for retrieving the current tiddler etc. +options: optional hashmap of options + options.defaultFilterRunPrefix: the default filter run prefix to use when none is specified */ -exports.compileFilter = function(filterString) { +exports.compileFilter = function(filterString,options) { + var defaultFilterRunPrefix = options?.defaultFilterRunPrefix || "or"; if(!this.filterCache) { this.filterCache = Object.create(null); this.filterCacheCount = 0; @@ -354,7 +357,7 @@ exports.compileFilter = function(filterString) { var options = {wiki: self, suffixes: operation.suffixes || []}; switch(operation.prefix || "") { case "": // No prefix means that the operation is unioned into the result - return filterRunPrefixes["or"](operationSubFunction, options); + return filterRunPrefixes[defaultFilterRunPrefix](operationSubFunction, options); case "=": // The results of the operation are pushed into the result without deduplication return filterRunPrefixes["all"](operationSubFunction, options); case "-": // The results of this operation are removed from the main result diff --git a/core/modules/filters/subfilter.js b/core/modules/filters/subfilter.js index 5e35f7cd1..c7853798e 100644 --- a/core/modules/filters/subfilter.js +++ b/core/modules/filters/subfilter.js @@ -13,7 +13,9 @@ Filter operator returning its operand evaluated as a filter Export our filter function */ exports.subfilter = function(source,operator,options) { - var list = options.wiki.filterTiddlers(operator.operand,options.widget,source); + var suffixes = operator.suffixes || [], + defaultFilterRunPrefix = (suffixes[0] || [])[0] || "or"; + var list = options.wiki.filterTiddlers(operator.operand,options.widget,source,{defaultFilterRunPrefix}); if(operator.prefix === "!") { var results = []; source(function(tiddler,title) {