Refactor dependency on widget.getVariableInfo

Fixing https://talk.tiddlywiki.org/t/tw-v5-3-0-pre-problem-with-autocomplete-plugin/6958/9?u=jeremyruston
This commit is contained in:
jeremy@jermolene.com 2023-06-11 09:46:05 +01:00
parent cc383e6d1e
commit 66212cd491
2 changed files with 17 additions and 2 deletions

View File

@ -12,6 +12,8 @@ Adds tiddler filtering methods to the $tw.Wiki object.
/*global $tw: false */
"use strict";
var widgetClass = require("$:/core/modules/widgets/widget.js").widget;
/* Maximum permitted filter recursion depth */
var MAX_FILTER_DEPTH = 300;
@ -269,8 +271,7 @@ exports.compileFilter = function(filterString) {
operand.value = self.getTextReference(operand.text,"",currTiddlerTitle);
} else if(operand.variable) {
var varTree = $tw.utils.parseFilterVariable(operand.text);
var variableInfo = widget.getVariableInfo(varTree.name,{params: varTree.params, source: source});
operand.value = (variableInfo.resultList ? variableInfo.resultList[0] : variableInfo.text) || "";
operand.value = widgetClass.evaluateVariable(widget,varTree.name,{params: varTree.params, source: source})[0] || "";
} else {
operand.value = operand.text;
}

View File

@ -796,6 +796,20 @@ Widget.prototype.allowActionPropagation = function() {
return true;
};
/*
Evaluate a variable with parameters. This is a static convenience method that attempts to evaluate a variable as a function, returning an array of strings
*/
Widget.evaluateVariable = function(widget,name,options) {
var result;
if(widget.getVariableInfo) {
var variableInfo = widget.getVariableInfo(name,options);
result = variableInfo.resultList || [variableInfo.text];
} else {
result = [widget.getVariable(name)];
}
return result;
};
exports.widget = Widget;
})();