Include specificity in popup ordering algorithm (#47)

This commit is contained in:
Maxim Baz
2019-03-20 00:01:16 +01:00
committed by GitHub
parent 59d215d389
commit fd2391e8f8

View File

@@ -154,8 +154,8 @@ function search(s) {
);
candidates = recent.concat(remainingInCurrentDomain);
}
candidates.sort(function(a, b) {
// sort most recent first
candidates.sort((a, b) => {
// show most recent first
if (a === mostRecent) {
return -1;
}
@@ -163,12 +163,21 @@ function search(s) {
return 1;
}
// sort by count
// sort by frequency
var countDiff = b.recent.count - a.recent.count;
if (countDiff) {
return countDiff;
}
// sort by specificity, only if filtering for one domain
if (this.currentDomainOnly) {
var domainLevelsDiff =
(b.login.match(/\./g) || []).length - (a.login.match(/\./g) || []).length;
if (domainLevelsDiff) {
return domainLevelsDiff;
}
}
// sort alphabetically
return a.login.localeCompare(b.login);
});