diff --git a/core/modules/filters/sort.js b/core/modules/filters/sort.js index f993825df..176cd4740 100644 --- a/core/modules/filters/sort.js +++ b/core/modules/filters/sort.js @@ -27,6 +27,12 @@ exports.nsort = function(source,operator,options) { return results; }; +exports.sortan = function(source, operator, options) { + var results = prepare_results(source); + options.wiki.sortTiddlers(results, operator.operand || "title", operator.prefix === "!",false,false,true); + return results; +}; + exports.sortcs = function(source,operator,options) { var results = prepare_results(source); options.wiki.sortTiddlers(results,operator.operand || "title",operator.prefix === "!",true,false); diff --git a/core/modules/wiki.js b/core/modules/wiki.js index 4500b7988..8db600ba6 100755 --- a/core/modules/wiki.js +++ b/core/modules/wiki.js @@ -329,7 +329,7 @@ Sort an array of tiddler titles by a specified field isDescending: true if the sort should be descending isCaseSensitive: true if the sort should consider upper and lower case letters to be different */ -exports.sortTiddlers = function(titles,sortField,isDescending,isCaseSensitive,isNumeric) { +exports.sortTiddlers = function(titles,sortField,isDescending,isCaseSensitive,isNumeric,isAlphaNumeric) { var self = this; titles.sort(function(a,b) { var x,y, @@ -358,6 +358,8 @@ exports.sortTiddlers = function(titles,sortField,isDescending,isCaseSensitive,is y = Number(b); if(isNumeric && (!isNaN(x) || !isNaN(y))) { return compareNumbers(x,y); + } else if(isAlphaNumeric) { + return isDescending ? b.localeCompare(a,undefined,{numeric: true,sensitivity:'base'}) : a.localeCompare(b,undefined,{numeric: true,sensitivity: 'base'}); } else if($tw.utils.isDate(a) && $tw.utils.isDate(b)) { return isDescending ? b - a : a - b; } else { diff --git a/editions/tw5.com/tiddlers/demonstrations/Apple.tid b/editions/tw5.com/tiddlers/demonstrations/Apple.tid new file mode 100644 index 000000000..becee440d --- /dev/null +++ b/editions/tw5.com/tiddlers/demonstrations/Apple.tid @@ -0,0 +1,6 @@ +created: 20180222072026299 +list: [[Apple 6]] [[Apple 7]] [[Apple 8]] [[Apple 9]] [[Apple 10]] [[Apple 20]] [[Apple 30]] [[Apple 100]] +modified: 20180222072215582 +tags: +title: Apple + diff --git a/editions/tw5.com/tiddlers/filters/examples/sortan.tid b/editions/tw5.com/tiddlers/filters/examples/sortan.tid new file mode 100644 index 000000000..d50c526f1 --- /dev/null +++ b/editions/tw5.com/tiddlers/filters/examples/sortan.tid @@ -0,0 +1,12 @@ +created: 20180222071947788 +modified: 20180222072601161 +tags: [[sortan Operator]] [[Operator Examples]] +title: sortan Operator (Examples) +type: text/vnd.tiddlywiki + +These examples make use of the [[Apple]] tiddler. + +<<.operator-example 1 "[list[Apple]sortan[]]">> +<<.operator-example 2 "[list[Apple]!sortan[]]">> +<<.operator-example 3 "App-10-A App-9-B App-10-B App-9-A +[sortan[]]">> + diff --git a/editions/tw5.com/tiddlers/filters/sortan.tid b/editions/tw5.com/tiddlers/filters/sortan.tid new file mode 100644 index 000000000..b6674c75b --- /dev/null +++ b/editions/tw5.com/tiddlers/filters/sortan.tid @@ -0,0 +1,16 @@ +caption: sortan +created: 20180222071605739 +modified: 20180223012553446 +op-input: a [[selection of titles|Title Selection]] +op-neg-output: the input, likewise sorted into descending order +op-output: the input, sorted into ascending order by field <<.field F>>, treating field values as alphanumerics +op-parameter: the name of a [[field|TiddlerFields]], defaulting to <<.field title>> +op-parameter-name: F +op-purpose: sort the input by text field considering them as alphanumerics +tags: [[Filter Operators]] [[Common Operators]] [[Field Operators]] [[Order Operators]] [[Negatable Operators]] +title: sortan Operator +type: text/vnd.tiddlywiki + +The difference between uppercase and lowercase letters is ignored. + +<<.operator-examples "sortan">>