From 54763ff7229448b1dbe01386341f0a1ec26301b9 Mon Sep 17 00:00:00 2001 From: abaevbog Date: Mon, 5 May 2025 20:23:59 -0700 Subject: [PATCH] improve performance of annotation rows removal (#5259) Do not update itemTree selection on each annotation row removal when an attachment row is collapsed. It causes a significant delay when attachment with many annotations is collapsed if selection is on any row below the attachment. It is also redundant because the selection is updated at the end of _closeContainer anyway. Fixes: #5255 --- chrome/content/zotero/itemTree.jsx | 5 ++++- chrome/content/zotero/libraryTree.js | 5 +++-- 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/chrome/content/zotero/itemTree.jsx b/chrome/content/zotero/itemTree.jsx index f872359c2f..9e61d39403 100644 --- a/chrome/content/zotero/itemTree.jsx +++ b/chrome/content/zotero/itemTree.jsx @@ -3346,7 +3346,10 @@ var ItemTree = class ItemTree extends LibraryTree { while ((index + 1 < this._rows.length) && (this.getLevel(index + 1) > level)) { // Skip the map update here and just refresh the whole map below, // since we might be removing multiple rows - this._removeRow(index + 1, true); + // Also, do not update the selection with each row removal for better performance + // when attachment with many annotations is being closed if the selection + // is already being restored in the end + this._removeRow(index + 1, true, !skipRowMapRefresh); count++; } diff --git a/chrome/content/zotero/libraryTree.js b/chrome/content/zotero/libraryTree.js index a749c0dc81..1325ad3005 100644 --- a/chrome/content/zotero/libraryTree.js +++ b/chrome/content/zotero/libraryTree.js @@ -155,11 +155,12 @@ var LibraryTree = class LibraryTree extends React.Component { * Remove a row from the main array and parent row children arrays, * delete the row from the map, and optionally update all rows above it in the map */ - _removeRow(index, skipMapUpdate) { + _removeRow(index, skipMapUpdate, skipSelectionUpdate) { var id = this.getRow(index).id; let level = this.getLevel(index); - if (index <= this.selection.focused) { + // Maintain selection unless specified otherwise + if (!skipSelectionUpdate && index <= this.selection.focused) { this.selection.select(this.selection.focused - 1); }