Don't scroll to containing collection if one is already visible
If multiple collections are highlighted and none are in view, scroll to the first one in the list. The logic could be improved here a little more to scroll to the closest collection instead of the first one, and also to scroll to a few rows above or below the target. This also fixes what was probably an incorrect highlight if there were multiple collections and some had to be expanded first.
This commit is contained in:
parent
a5eb5a5af5
commit
2c25257e2b
1 changed files with 29 additions and 8 deletions
|
@ -384,17 +384,38 @@ Zotero.CollectionTreeView.prototype.setHighlightedRows = function (ids) {
|
|||
this._highlightedRows = {};
|
||||
this._treebox.invalidate();
|
||||
|
||||
var scrolled = false;
|
||||
for each(var id in ids) {
|
||||
let row = this._collectionRowMap[id];
|
||||
if (!ids || !ids.length) {
|
||||
return;
|
||||
}
|
||||
|
||||
// Make sure all highlighted collections are shown
|
||||
for (let id of ids) {
|
||||
this.expandToCollection(id);
|
||||
// TODO: Scroll a little above or below
|
||||
if (!scrolled) {
|
||||
this._treebox.ensureRowIsVisible(row);
|
||||
scrolled = true;
|
||||
}
|
||||
}
|
||||
|
||||
// Highlight rows
|
||||
var rows = [];
|
||||
for (let id of ids) {
|
||||
let row = this._collectionRowMap[id];
|
||||
this._highlightedRows[row] = true;
|
||||
this._treebox.invalidateRow(row);
|
||||
rows.push(row);
|
||||
}
|
||||
rows.sort();
|
||||
var firstRow = this._treebox.getFirstVisibleRow();
|
||||
var lastRow = this._treebox.getLastVisibleRow();
|
||||
var scrolled = false;
|
||||
for (let row of rows) {
|
||||
// If row is visible, stop
|
||||
if (row >= firstRow && row <= lastRow) {
|
||||
scrolled = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
// Select first collection
|
||||
// TODO: Select closest? Select a few rows above or below?
|
||||
if (!scrolled) {
|
||||
this._treebox.ensureRowIsVisible(rows[0]);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue