commit bb246e5514596030f8c02540713bfb611e572a62
parent 142694ca0f43455411ea395a8cba45b797401640
Author: Dan Stillman <dstillman@zotero.org>
Date: Fri, 9 Dec 2016 06:08:45 -0500
Scroll first selected row into view in itemTreeView::selectItems()
Separate out the enhanced ensureRowIsVisible() logic from selectItem()
and call it from selectItems() as well on the first item in the set.
Diffstat:
1 file changed, 24 insertions(+), 17 deletions(-)
diff --git a/chrome/content/zotero/xpcom/itemTreeView.js b/chrome/content/zotero/xpcom/itemTreeView.js
@@ -1748,23 +1748,7 @@ Zotero.ItemTreeView.prototype.selectItem = Zotero.Promise.coroutine(function* (i
yield deferred.promise;
}
- // We aim for a row 5 below the target row, since ensureRowIsVisible() does
- // the bare minimum to get the row in view
- for (var v = row + 5; v>=row; v--) {
- if (this._rows[v]) {
- this._treebox.ensureRowIsVisible(v);
- if (this._treebox.getFirstVisibleRow() <= row) {
- break;
- }
- }
- }
-
- // If the parent row isn't in view and we have enough room, make parent visible
- if (parentRow !== null && this._treebox.getFirstVisibleRow() > parentRow) {
- if ((row - parentRow) < this._treebox.getPageLength()) {
- this._treebox.ensureRowIsVisible(parentRow);
- }
- }
+ this.betterEnsureRowIsVisible(row, parentRow);
return true;
});
@@ -1801,9 +1785,32 @@ Zotero.ItemTreeView.prototype.selectItems = function(ids) {
}
this.selection.selectEventsSuppressed = false;
+ // TODO: This could probably be improved to try to focus more of the selected rows
+ this.betterEnsureRowIsVisible(rows[0]);
}
+Zotero.ItemTreeView.prototype.betterEnsureRowIsVisible = function (row, parentRow = null) {
+ // We aim for a row 5 below the target row, since ensureRowIsVisible() does
+ // the bare minimum to get the row in view
+ for (let v = row + 5; v >= row; v--) {
+ if (this._rows[v]) {
+ this._treebox.ensureRowIsVisible(v);
+ if (this._treebox.getFirstVisibleRow() <= row) {
+ break;
+ }
+ }
+ }
+
+ // If the parent row isn't in view and we have enough room, make parent visible
+ if (parentRow !== null && this._treebox.getFirstVisibleRow() > parentRow) {
+ if ((row - parentRow) < this._treebox.getPageLength()) {
+ this._treebox.ensureRowIsVisible(parentRow);
+ }
+ }
+};
+
+
/*
* Return an array of Item objects for selected items
*