Scroll to new collections, and stay on same row when deleting collections

This commit is contained in:
Dan Stillman 2014-08-12 22:19:19 -04:00
parent 6dbcdb95f4
commit 9db4927f78
2 changed files with 12 additions and 6 deletions

View File

@ -245,7 +245,7 @@ Zotero.CollectionTreeView.prototype.notify = Zotero.Promise.coroutine(function*
var savedSelection = this.saveSelection(); var savedSelection = this.saveSelection();
if (action == 'delete') { if (action == 'delete') {
var selectedIndex = this.selection.count ? this.selection.selectedIndex : 0; var selectedIndex = this.selection.count ? this.selection.currentIndex : 0;
//Since a delete involves shifting of rows, we have to do it in order //Since a delete involves shifting of rows, we have to do it in order
@ -287,14 +287,18 @@ Zotero.CollectionTreeView.prototype.notify = Zotero.Promise.coroutine(function*
for(var i=0, len=rows.length; i<len; i++) for(var i=0, len=rows.length; i<len; i++)
{ {
var row = rows[i]; var row = rows[i];
this._removeRow(row-i); this._removeRow(row);
this._treebox.rowCountChanged(row-i,-1); this._treebox.rowCountChanged(row, -1);
} }
this._refreshCollectionRowMap(); this._refreshCollectionRowMap();
} }
if (!this.selection.count) { if (!this.selection.count) {
// If last row was selected, stay on the last row
if (selectedIndex >= this.rowCount) {
selectedIndex = this.rowCount - 1;
};
this.selection.select(selectedIndex) this.selection.select(selectedIndex)
} }
} }
@ -343,7 +347,9 @@ Zotero.CollectionTreeView.prototype.notify = Zotero.Promise.coroutine(function*
this.rememberSelection(savedSelection); this.rememberSelection(savedSelection);
break; break;
} }
this.selection.select(this._collectionRowMap[collection.id]); let row = this._collectionRowMap[collection.id];
this._treebox.ensureRowIsVisible(row);
this.selection.select(row);
break; break;
case 'search': case 'search':

View File

@ -646,12 +646,12 @@ Zotero.ItemTreeView.prototype.notify = Zotero.Promise.coroutine(function* (actio
// The container refresh above takes care of adding the new row. // The container refresh above takes care of adding the new row.
else if (!this.isContainer(row) && parentIndex == -1 && parentItemID) { else if (!this.isContainer(row) && parentIndex == -1 && parentItemID) {
this._removeRow(row); this._removeRow(row);
this._treebox.rowCountChanged(row + 1, -1) this._treebox.rowCountChanged(row, -1)
} }
// If moved from under another item to top level, remove old row and add new one // If moved from under another item to top level, remove old row and add new one
else if (!this.isContainer(row) && parentIndex != -1 && !parentItemID) { else if (!this.isContainer(row) && parentIndex != -1 && !parentItemID) {
this._removeRow(row); this._removeRow(row);
this._treebox.rowCountChanged(row + 1, -1) this._treebox.rowCountChanged(row, -1)
this._addRow( this._addRow(
this._rows, this._rows,