From 7ec89c44ce0277497cf7b23659c1b3555caa356e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Adomas=20Ven=C4=8Dkauskas?= Date: Fri, 23 Apr 2021 10:48:43 +0300 Subject: [PATCH] Improve column sorting speed --- .../content/zotero/components/virtualized-table.jsx | 2 ++ chrome/content/zotero/itemTree.jsx | 13 ++++++++----- 2 files changed, 10 insertions(+), 5 deletions(-) diff --git a/chrome/content/zotero/components/virtualized-table.jsx b/chrome/content/zotero/components/virtualized-table.jsx index 8da5c0e95e..43ccc3e1a2 100644 --- a/chrome/content/zotero/components/virtualized-table.jsx +++ b/chrome/content/zotero/components/virtualized-table.jsx @@ -100,6 +100,8 @@ class TreeSelection { clearSelection() { this.selected = new Set(); + if (this.selectEventsSuppressed) return; + if (this._tree.invalidate) { this._tree.invalidate(); } diff --git a/chrome/content/zotero/itemTree.jsx b/chrome/content/zotero/itemTree.jsx index 3c7fb8a919..d5587dc067 100644 --- a/chrome/content/zotero/itemTree.jsx +++ b/chrome/content/zotero/itemTree.jsx @@ -1609,13 +1609,15 @@ var ItemTree = class ItemTree extends LibraryTree { this._rows.sort((a, b) => rowSort(a, b) * order); } - this.tree && this.tree.invalidate(); - this._refreshRowMap(); this._rememberOpenState(openItemIDs); this._restoreSelection(savedSelection); + if (this.tree && !this.selection.selectEventsSuppressed) { + this.tree.invalidate(); + } + var numSorted = itemIDs ? itemIDs.length : this._rows.length; Zotero.debug(`Sorted ${numSorted} ${Zotero.Utilities.pluralize(numSorted, ['item', 'items'])} ` + `in ${new Date - t} ms`); @@ -3154,14 +3156,15 @@ var ItemTree = class ItemTree extends LibraryTree { } } - this._storeColumnPrefs(columnSettings); await this._refreshPromise; this.selection.selectEventsSuppressed = true; await this.sort(); this.forceUpdate(() => { - this.tree.invalidate(); this.selection.selectEventsSuppressed = false; - }) + // Store column prefs as a final action because it freezes the UI momentarily + // and makes the column sorting look laggy + this._storeColumnPrefs(columnSettings); + }); } _displayColumnPickerMenu = (event) => {