From 3e37d31a493a8d1b391d828f98408ed3efcb6f14 Mon Sep 17 00:00:00 2001 From: Dan Stillman Date: Wed, 24 Feb 2021 01:36:14 -0500 Subject: [PATCH] Sort notes reverse chronologically in note insertion search results --- chrome/content/zotero/integration/quickFormat.js | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/chrome/content/zotero/integration/quickFormat.js b/chrome/content/zotero/integration/quickFormat.js index 065fb9678b..77257aae2b 100644 --- a/chrome/content/zotero/integration/quickFormat.js +++ b/chrome/content/zotero/integration/quickFormat.js @@ -503,7 +503,7 @@ var Zotero_QuickFormat = new function () { searchString = searchString.toLowerCase(); var collation = Zotero.getLocaleCollation(); - items.sort(function _itemSort(a, b) { + function _itemSort(a, b) { var firstCreatorA = a.firstCreator, firstCreatorB = b.firstCreator; // Favor left-bound name matches (e.g., "Baum" < "Appelbaum"), @@ -549,7 +549,15 @@ var Zotero_QuickFormat = new function () { var yearA = a.getField("date", true, true).substr(0, 4), yearB = b.getField("date", true, true).substr(0, 4); return yearA - yearB; - }); + } + + function _noteSort(a, b) { + return collation.compareString( + 1, b.getField('dateModified'), a.getField('dateModified') + ); + } + + items.sort(Zotero_QuickFormat.citingNotes ? _noteSort : _itemSort); var previousLibrary = -1; for(var i=0, n=Math.min(items.length, citedItemsMatchingSearch ? 50-citedItemsMatchingSearch.length : 50); i