commit 796a1a2898d52617b3841468fd63934b31078663
parent 2f3d865f11a5db3dd77f355bcda88a86e287108d
Author: Dan Stillman <dstillman@zotero.org>
Date: Mon, 6 Apr 2015 23:32:15 -0400
Use firstCreator instead of creators[0] for QuickFormat sort
Previously, if an editor was entered before an author, it would sort by
the editor. Now, as long as there's an author, it will sort by that
first (and, with 2f3d865f, favor left-bound matches).
Addresses the second issue on
https://forums.zotero.org/discussion/48047/
Diffstat:
1 file changed, 11 insertions(+), 9 deletions(-)
diff --git a/chrome/content/zotero/integration/quickFormat.js b/chrome/content/zotero/integration/quickFormat.js
@@ -412,16 +412,16 @@ var Zotero_QuickFormat = new function () {
var items = Zotero.Items.get(searchResultIDs);
searchString = searchString.toLowerCase();
+ var collation = Zotero.getLocaleCollation();
items.sort(function _itemSort(a, b) {
- var creatorsA = a.getCreators(), creatorsB = b.getCreators(),
- caExists = creatorsA.length ? 1 : 0, cbExists = creatorsB.length ? 1 : 0;
+ var firstCreatorA = a.firstCreator, firstCreatorB = b.firstCreator;
// Favor left-bound name matches (e.g., "Baum" < "Appelbaum"),
// using last name of first author
- if (caExists && cbExists) {
- let caStartsWith = creatorsA[0].ref.lastName.toLowerCase().indexOf(searchString) == 0;
- let cbStartsWith = creatorsB[0].ref.lastName.toLowerCase().indexOf(searchString) == 0;
+ if (firstCreatorA && firstCreatorB) {
+ let caStartsWith = firstCreatorA.toLowerCase().indexOf(searchString) == 0;
+ let cbStartsWith = firstCreatorB.toLowerCase().indexOf(searchString) == 0;
if (caStartsWith && !cbStartsWith) {
return -1;
}
@@ -448,10 +448,12 @@ var Zotero_QuickFormat = new function () {
}
// Sort by last name of first author
- if(caExists !== cbExists) {
- return cbExists-caExists;
- } else if(caExists) {
- return creatorsA[0].ref.lastName.localeCompare(creatorsB[0].ref.lastName);
+ if (firstCreatorA !== "" && firstCreatorB === "") {
+ return -1;
+ } else if (firstCreatorA === "" && firstCreatorB !== "") {
+ return 1
+ } else if (firstCreatorA) {
+ return collation.compareString(1, firstCreatorA, firstCreatorB);
}
// Sort by date