Add alphabetical secondary sort when bringing prefix matches to the top

This commit is contained in:
dloverin committed 2013-03-29 14:48:50 -04:00
1 parent 4e6c8f5091
commit d947130020
1 file changed
+23 -2
@@ -129,6 +129,27 @@ define(function (require, exports, module) {
}
}
/*
* Comparator for sorting tokens by name
*
* @param {Object} a - a token
* @param {Object} b - another token
* @return {number} - comparator value that indicates whether the name
* of token a is lexicographically lower than the name of token b
*/
function compareByName(a, b) {
var aLowerCase = a.value.toLowerCase();
var bLowerCase = b.value.toLowerCase();
if (aLowerCase === bLowerCase) {
return 0;
} else if (aLowerCase < bLowerCase) {
return -1;
} else {
return 1;
}
}
/*
* Returns a formatted list of hints with the query substring
* highlighted.
@@ -150,8 +171,8 @@ define(function (require, exports, module) {
} else if (index1 !== 0 && index2 === 0) {
return 1;
}
return 0;
return compareByName(hint1, hint2);
});
}