diff --git a/core/modules/filters/tag.js b/core/modules/filters/tag.js index 7c5fdb794..7ae4f9191 100644 --- a/core/modules/filters/tag.js +++ b/core/modules/filters/tag.js @@ -40,6 +40,10 @@ exports.tag = function(source,operator,options) { checkTiddler(title); }); } + // Sort the results if we are matching a tag + if(operator.prefix !== "!") { + results = options.wiki.sortByList(results,operator.operand); + } return results; }; diff --git a/core/modules/wiki.js b/core/modules/wiki.js index 1dff1381d..1289b7507 100644 --- a/core/modules/wiki.js +++ b/core/modules/wiki.js @@ -411,6 +411,7 @@ exports.getShadowTitles = function() { Retrieves a list of the tiddler titles that are tagged with a given tag */ exports.getTiddlersWithTag = function(tag) { + // Get the list associated with the tag var titles = []; for(var title in this.tiddlers) { var tiddler = this.tiddlers[title]; @@ -418,7 +419,34 @@ exports.getTiddlersWithTag = function(tag) { titles.push(title); } } - return titles; + return this.sortByList(titles,tag); +}; + +/* +Sorts an array of tiddler titles according to an ordered list +*/ +exports.sortByList = function(array,listTitle) { + var list = this.getTiddlerList(listTitle); + if(list) { + var titles = [], t, title; + // First place any entries that are present in the list + for(t=0; t
<$view field="title" format="link" /> ---- -<$list filter="[is[current]tagging[]sort[title]]"> +<$list filter="[is[current]tagging[]]"> <$view field="title" format="link" />
diff --git a/editions/test/tiddlers/tests/test-filters.js b/editions/test/tiddlers/tests/test-filters.js index 7e0d59bda..50410e764 100644 --- a/editions/test/tiddlers/tests/test-filters.js +++ b/editions/test/tiddlers/tests/test-filters.js @@ -114,7 +114,7 @@ describe("Filter tests", function() { it("should handle the tagging operator", function() { expect(wiki.filterTiddlers("[[one]tagging[]sort[title]]").join(",")).toBe("Tiddler Three,TiddlerOne"); - expect(wiki.filterTiddlers("[[one]tagging[]]").join(",")).toBe("TiddlerOne,Tiddler Three"); + expect(wiki.filterTiddlers("[[one]tagging[]]").join(",")).toBe("Tiddler Three,TiddlerOne"); expect(wiki.filterTiddlers("[[two]tagging[]sort[title]]").join(",")).toBe("$:/TiddlerTwo,Tiddler Three"); expect(wiki.filterTiddlers("[is[current]tagging[]sort[title]]","one").join(",")).toBe("Tiddler Three,TiddlerOne"); }); diff --git a/editions/tw5.com/tiddlers/tags/introduction.tid b/editions/tw5.com/tiddlers/tags/introduction.tid index 85c99f0b5..9bc0a6b28 100644 --- a/editions/tw5.com/tiddlers/tags/introduction.tid +++ b/editions/tw5.com/tiddlers/tags/introduction.tid @@ -1,4 +1,4 @@ title: introduction modified: 201306041707 color: plum - +list: HelloThere Acknowledgements Improvements Demos [[TiddlyWiki5 Editions]] Docs DeveloperDocs