Skip to content

Include specificity in popup ordering algorithm #47

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Mar 19, 2019
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 12 additions & 3 deletions src/popup/interface.js
Original file line number Diff line number Diff line change
Expand Up @@ -154,21 +154,30 @@ 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;
}
if (b === mostRecent) {
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);
});
Expand Down