diff --git a/chrome/content/zotero/overlay.js b/chrome/content/zotero/overlay.js index 631d92156..6eef83581 100644 --- a/chrome/content/zotero/overlay.js +++ b/chrome/content/zotero/overlay.js @@ -287,8 +287,8 @@ var ZoteroOverlay = new function() */ this.toggleTab = function(setMode) { var tab = this.findZoteroTab(); + window.zoteroSavedCollectionSelection = ZoteroPane.collectionsView.selectedTreeRow.id; window.zoteroSavedItemSelection = ZoteroPane.itemsView.saveSelection(); - window.zoteroSavedCollectionSelection = ZoteroPane.collectionsView.saveSelection(); if(tab) { // Zotero is running in a tab if(setMode) return; // if Zotero tab is the only tab, open the home page in a new tab diff --git a/chrome/content/zotero/xpcom/itemTreeView.js b/chrome/content/zotero/xpcom/itemTreeView.js index 3d182f809..920776eb1 100644 --- a/chrome/content/zotero/xpcom/itemTreeView.js +++ b/chrome/content/zotero/xpcom/itemTreeView.js @@ -923,6 +923,11 @@ Zotero.ItemTreeView.prototype.unregister = function() { Zotero.Notifier.unregisterObserver(this._unregisterID); if (this.listener) { + if (!this._treebox.treeBody) { + Zotero.debug("No more tree body in Zotero.ItemTreeView::unregister()"); + this.listener = null; + return; + } let tree = this._treebox.treeBody.parentNode; tree.removeEventListener('keypress', this.listener, false); this.listener = null; diff --git a/chrome/content/zotero/zoteroPane.js b/chrome/content/zotero/zoteroPane.js index 48e9c2ac6..6c835677e 100644 --- a/chrome/content/zotero/zoteroPane.js +++ b/chrome/content/zotero/zoteroPane.js @@ -377,20 +377,18 @@ var ZoteroPane = new function() // restore saved row selection (for tab switching) var containerWindow = (window.ZoteroTab ? window.ZoteroTab.containerWindow : window); if(containerWindow.zoteroSavedCollectionSelection) { - yield this.collectionsView.rememberSelection(containerWindow.zoteroSavedCollectionSelection); - delete containerWindow.zoteroSavedCollectionSelection; - } - - // restore saved item selection (for tab switching) - if(containerWindow.zoteroSavedItemSelection) { - let self = this; - // hack to restore saved selection after itemTreeView finishes loading - window.setTimeout(function() { - if(containerWindow.zoteroSavedItemSelection) { - yield self.itemsView.rememberSelection(containerWindow.zoteroSavedItemSelection); - delete containerWindow.zoteroSavedItemSelection; + this.collectionsView.addEventListener('load', Zotero.Promise.coroutine(function* () { + yield this.collectionsView.selectByID(containerWindow.zoteroSavedCollectionSelection); + + if (containerWindow.zoteroSavedItemSelection) { + this.itemsView.addEventListener('load', function () { + this.itemsView.rememberSelection(containerWindow.zoteroSavedItemSelection); + delete containerWindow.zoteroSavedItemSelection; + }.bind(this)); } - }, 51); + + delete containerWindow.zoteroSavedCollectionSelection; + }.bind(this))); } // Focus the quicksearch on pane open