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
This commit is contained in:
abaevbog 2025-05-05 20:23:59 -07:00 • committed by GitHub
parent 31845457a2
commit 54763ff722
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 7 additions and 3 deletions

View file

@ -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++;
}

View file

@ -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);
}