From b05e22fa77d67f7449ee6116f385a955b02b12f1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Adomas=20Ven=C4=8Dkauskas?= Date: Fri, 27 Aug 2021 13:36:03 +0300 Subject: [PATCH] HTML Tree: Make search context rows selectable. Closes #2164 Adds special handling such that context rows are not selected only when performing a select-all. --- chrome/content/zotero/components/virtualized-table.jsx | 10 +++++----- chrome/content/zotero/itemTree.jsx | 9 +++++++-- 2 files changed, 12 insertions(+), 7 deletions(-) diff --git a/chrome/content/zotero/components/virtualized-table.jsx b/chrome/content/zotero/components/virtualized-table.jsx index 9e5a3142bd..4c0498aac1 100644 --- a/chrome/content/zotero/components/virtualized-table.jsx +++ b/chrome/content/zotero/components/virtualized-table.jsx @@ -138,21 +138,21 @@ class TreeSelection { return true; } - _rangedSelect(from, to, augment) { + _rangedSelect(from, to, augment, isSelectAll) { from = Math.max(0, from); to = Math.max(0, to); if (!augment) { this.selected = new Set(); } for (let i = from; i <= to; i++) { - if (this._tree.props.isSelectable(i)) { + if (this._tree.props.isSelectable(i, isSelectAll)) { this.selected.add(i); } } } - rangedSelect(from, to, augment) { - this._rangedSelect(from, to, augment); + rangedSelect(from, to, augment, isSelectAll) { + this._rangedSelect(from, to, augment, isSelectAll); if (this.selectEventsSuppressed) return; @@ -554,7 +554,7 @@ class VirtualizedTable extends React.Component { case "a": // i.e. if CTRL/CMD pressed down - if (movePivot) this.selection.rangedSelect(0, this.props.getRowCount()-1); + if (movePivot) this.selection.rangedSelect(0, this.props.getRowCount()-1, false, true); break; case " ": diff --git a/chrome/content/zotero/itemTree.jsx b/chrome/content/zotero/itemTree.jsx index 7731efe55c..6c276beb57 100644 --- a/chrome/content/zotero/itemTree.jsx +++ b/chrome/content/zotero/itemTree.jsx @@ -1841,8 +1841,13 @@ var ItemTree = class ItemTree extends LibraryTree { return fields; } - isSelectable = (index) => { - if (!this._searchMode || this.collectionTreeRow.isPublications()) return true; + /** + * @param index {Integer} + * @param selectAll {Boolean} Whether the selection is part of a select-all event + * @returns {Boolean} + */ + isSelectable = (index, selectAll=false) => { + if (!selectAll || !this._searchMode || this.collectionTreeRow.isPublications()) return true; let row = this.getRow(index); return row && this._searchItemIDs.has(row.id); }