1
0
mirror of https://github.com/Jermolene/TiddlyWiki5 synced 2025-08-07 22:33:50 +00:00

Remove duplicates from filter tracker results

This commit is contained in:
Jeremy Ruston 2025-01-06 16:43:02 +00:00
parent ed2c7c90de
commit 806960afc7

View File

@ -64,14 +64,19 @@ FilterTracker.prototype.processTrackers = function() {
}; };
FilterTracker.prototype.processTracker = function(index) { FilterTracker.prototype.processTracker = function(index) {
var tracker = this.trackers[index], var tracker = this.trackers[index];
results = this.wiki.filterTiddlers(tracker.filterString); var results = [];
// Process the results // Evaluate the filter and remove duplicate results
$tw.utils.each(this.wiki.filterTiddlers(tracker.filterString),function(title) {
$tw.utils.pushTop(results,title);
});
// Process the newly entered results
$tw.utils.each(results,function(title) { $tw.utils.each(results,function(title) {
if(tracker.previousResults.indexOf(title) === -1 && !tracker.resultValues[title] && tracker.fnEnter) { if(tracker.previousResults.indexOf(title) === -1 && !tracker.resultValues[title] && tracker.fnEnter) {
tracker.resultValues[title] = tracker.fnEnter(title) || true; tracker.resultValues[title] = tracker.fnEnter(title) || true;
} }
}); });
// Process the results that have just left
$tw.utils.each(tracker.previousResults,function(title) { $tw.utils.each(tracker.previousResults,function(title) {
if(results.indexOf(title) === -1 && tracker.resultValues[title] && tracker.fnLeave) { if(results.indexOf(title) === -1 && tracker.resultValues[title] && tracker.fnLeave) {
tracker.fnLeave(title,tracker.resultValues[title]); tracker.fnLeave(title,tracker.resultValues[title]);
@ -86,7 +91,7 @@ FilterTracker.prototype.processChanges = function(changes) {
for(var t=0; t<this.trackers.length; t++) { for(var t=0; t<this.trackers.length; t++) {
var tracker = this.trackers[t]; var tracker = this.trackers[t];
$tw.utils.each(changes,function(change,title) { $tw.utils.each(changes,function(change,title) {
if(tracker.previousResults.indexOf(title) !== -1 && tracker.fnChange) { if(title && tracker.previousResults.indexOf(title) !== -1 && tracker.fnChange) {
// Call the change function and if it doesn't return a value then keep the old value // Call the change function and if it doesn't return a value then keep the old value
tracker.resultValues[title] = tracker.fnChange(title,tracker.resultValues[title]) || tracker.resultValues[title]; tracker.resultValues[title] = tracker.fnChange(title,tracker.resultValues[title]) || tracker.resultValues[title];
} }