1
0
mirror of https://github.com/Jermolene/TiddlyWiki5 synced 2024-11-26 03:27:18 +00:00

Fix last filter operator when zero items selected (#7809)

Previously, [last[0]] was incorrectly returning the entire list. It now
returns zero items as it should.
This commit is contained in:
Robin Munn 2023-10-25 19:14:49 +07:00 committed by GitHub
parent 4ebaba8e89
commit 246751be1b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 2 additions and 0 deletions

View File

@ -58,6 +58,7 @@ Last entry/entries in list
exports.last = function(source,operator,options) { exports.last = function(source,operator,options) {
var count = $tw.utils.getInt(operator.operand,1), var count = $tw.utils.getInt(operator.operand,1),
results = []; results = [];
if(count === 0) return results;
source(function(tiddler,title) { source(function(tiddler,title) {
results.push(title); results.push(title);
}); });

View File

@ -365,6 +365,7 @@ Tests the filtering mechanism.
expect(wiki.filterTiddlers("[sort[title]first[8]]").join(",")).toBe("$:/ShadowPlugin,$:/TiddlerTwo,a fourth tiddler,filter regexp test,has filter,hasList,one,Tiddler Three"); expect(wiki.filterTiddlers("[sort[title]first[8]]").join(",")).toBe("$:/ShadowPlugin,$:/TiddlerTwo,a fourth tiddler,filter regexp test,has filter,hasList,one,Tiddler Three");
expect(wiki.filterTiddlers("[sort[title]first[x]]").join(",")).toBe("$:/ShadowPlugin"); expect(wiki.filterTiddlers("[sort[title]first[x]]").join(",")).toBe("$:/ShadowPlugin");
expect(wiki.filterTiddlers("[sort[title]last[]]").join(",")).toBe("TiddlerOne"); expect(wiki.filterTiddlers("[sort[title]last[]]").join(",")).toBe("TiddlerOne");
expect(wiki.filterTiddlers("[sort[title]last[0]]").join(",")).toBe("");
expect(wiki.filterTiddlers("[sort[title]last[2]]").join(",")).toBe("Tiddler Three,TiddlerOne"); expect(wiki.filterTiddlers("[sort[title]last[2]]").join(",")).toBe("Tiddler Three,TiddlerOne");
expect(wiki.filterTiddlers("[sort[title]last[8]]").join(",")).toBe("$:/TiddlerTwo,a fourth tiddler,filter regexp test,has filter,hasList,one,Tiddler Three,TiddlerOne"); expect(wiki.filterTiddlers("[sort[title]last[8]]").join(",")).toBe("$:/TiddlerTwo,a fourth tiddler,filter regexp test,has filter,hasList,one,Tiddler Three,TiddlerOne");
expect(wiki.filterTiddlers("[sort[title]last[x]]").join(",")).toBe("TiddlerOne"); expect(wiki.filterTiddlers("[sort[title]last[x]]").join(",")).toBe("TiddlerOne");