From ad36c9fb2a9442803760f076f1734f2be5d6aa09 Mon Sep 17 00:00:00 2001 From: Abe Jellinek Date: Mon, 11 Apr 2022 10:13:50 -0700 Subject: [PATCH] Context Pane: Sort notes in item tree order Fixes #2526. --- chrome/content/zotero/contextPane.js | 20 +++++++++++++++----- 1 file changed, 15 insertions(+), 5 deletions(-) diff --git a/chrome/content/zotero/contextPane.js b/chrome/content/zotero/contextPane.js index 2d364b9016..21ca3d03c8 100644 --- a/chrome/content/zotero/contextPane.js +++ b/chrome/content/zotero/contextPane.js @@ -538,11 +538,21 @@ var ZoteroContextPane = new function () { } notes = await s.search(); notes = Zotero.Items.get(notes); - notes.sort((a, b) => { - a = a.dateModified; - b = b.dateModified; - return (a > b ? -1 : (a < b ? 1 : 0)); - }); + if (Zotero.Prefs.get('sortNotesChronologically')) { + notes.sort((a, b) => { + a = a.dateModified; + b = b.dateModified; + return (a > b ? -1 : (a < b ? 1 : 0)); + }); + } + else { + let collation = Zotero.getLocaleCollation(); + notes.sort((a, b) => { + let aTitle = Zotero.Items.getSortTitle(a.getField('title')); + let bTitle = Zotero.Items.getSortTitle(b.getField('title')); + return collation.compareString(1, aTitle, bTitle); + }); + } let cachedNotesIndex = new Map(); for (let cachedNote of context.cachedNotes) {