Sorts first-author last name matches first when year present. (#3025)

Closes #3024
This commit is contained in:
Adomas Ven 2023-03-19 02:52:54 +02:00 committed by GitHub
parent 14bb46f434
commit e024449732
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -499,6 +499,7 @@ var Zotero_QuickFormat = new function () {
await Zotero.Items.loadDataTypes(items);
searchString = searchString.toLowerCase();
let searchParts = Zotero.SearchConditions.parseSearchString(searchString);
var collation = Zotero.getLocaleCollation();
function _itemSort(a, b) {
@ -507,13 +508,15 @@ var Zotero_QuickFormat = new function () {
// Favor left-bound name matches (e.g., "Baum" < "Appelbaum"),
// using last name of first author
if (firstCreatorA && firstCreatorB) {
let caStartsWith = firstCreatorA.toLowerCase().indexOf(searchString) == 0;
let cbStartsWith = firstCreatorB.toLowerCase().indexOf(searchString) == 0;
if (caStartsWith && !cbStartsWith) {
return -1;
}
else if (!caStartsWith && cbStartsWith) {
return 1;
for (let part of searchParts) {
let caStartsWith = firstCreatorA.toLowerCase().startsWith(part.text);
let cbStartsWith = firstCreatorB.toLowerCase().startsWith(part.text);
if (caStartsWith && !cbStartsWith) {
return -1;
}
else if (!caStartsWith && cbStartsWith) {
return 1;
}
}
}