From 87014451de41c9640e1554d1dae35f2ac9bce21a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Adomas=20Ven=C4=8Dkauskas?= Date: Wed, 14 Apr 2021 12:16:39 +0300 Subject: [PATCH] Fix item tree selection issues when using + and - hotkeys --- chrome/content/zotero/itemTree.jsx | 26 +++++++++++++++++++++----- 1 file changed, 21 insertions(+), 5 deletions(-) diff --git a/chrome/content/zotero/itemTree.jsx b/chrome/content/zotero/itemTree.jsx index c7210d770c..decb66c07c 100644 --- a/chrome/content/zotero/itemTree.jsx +++ b/chrome/content/zotero/itemTree.jsx @@ -3052,13 +3052,23 @@ var ItemTree = class ItemTree extends LibraryTree { var unsuppress = this.selection.selectEventsSuppressed = true; } + let focusedSet = false; + var toggleSelect = (function (itemID) { + if (!focusedSet) { + this.selection.select(this._rowMap[itemID]); + focusedSet = true; + } + else { + this.selection.toggleSelect(this._rowMap[itemID]); + } + }).bind(this); try { for (let i = 0; i < selection.length; i++) { if (this._rowMap[selection[i]] != null) { - this.selection.toggleSelect(this._rowMap[selection[i]]); + toggleSelect(selection[i]); } // Try the parent - else if (expandCollapsedParents) { + else { var item = Zotero.Items.get(selection[i]); if (!item) { continue; @@ -3070,9 +3080,15 @@ var ItemTree = class ItemTree extends LibraryTree { } if (this._rowMap[parent] != null) { - await this._closeContainer(this._rowMap[parent]); - await this.toggleOpenState(this._rowMap[parent]); - this.selection.toggleSelect(this._rowMap[selection[i]]); + if (expandCollapsedParents) { + await this._closeContainer(this._rowMap[parent]); + await this.toggleOpenState(this._rowMap[parent]); + toggleSelect(selection[i]); + } + else { + !this.selection.isSelected(this._rowMap[parent]) && + toggleSelect(parent); + } } } }