From 374eefada10d254fedc61147c2467d9933ea654c Mon Sep 17 00:00:00 2001 From: Dan Stillman Date: Tue, 2 Jan 2018 20:17:51 -0500 Subject: [PATCH] Additional try/catch to fix NS_ERROR_UNEXPECTED from tree select Follow-up to 7cd1439928 --- chrome/content/zotero/xpcom/itemTreeView.js | 37 +++++++++++++-------- 1 file changed, 23 insertions(+), 14 deletions(-) diff --git a/chrome/content/zotero/xpcom/itemTreeView.js b/chrome/content/zotero/xpcom/itemTreeView.js index 84854b45e2..7e138a09f4 100644 --- a/chrome/content/zotero/xpcom/itemTreeView.js +++ b/chrome/content/zotero/xpcom/itemTreeView.js @@ -1869,20 +1869,29 @@ Zotero.ItemTreeView.prototype.selectItem = Zotero.Promise.coroutine(function* (i // refreshed. To get around this, we wait for a select event that's triggered by // itemSelected() when it's done. let promise; - if (this.selection.selectEventsSuppressed) { + try { + if (this.selection.selectEventsSuppressed) { + this.selection.select(row); + } + else { + promise = this.waitForSelect(); + this.selection.select(row); + } + + // If |expand|, open row if container + if (expand && this.isContainer(row) && !this.isContainerOpen(row)) { + this.toggleOpenState(row); + } this.selection.select(row); } - else { - promise = this.waitForSelect(); - this.selection.select(row); + // Ignore NS_ERROR_UNEXPECTED from nsITreeSelection::select(), apparently when the tree + // disappears before it's called (though I can't reproduce it): + // + // https://forums.zotero.org/discussion/comment/297039/#Comment_297039 + catch (e) { + Zotero.logError(e); } - // If |expand|, open row if container - if (expand && this.isContainer(row) && !this.isContainerOpen(row)) { - this.toggleOpenState(row); - } - this.selection.select(row); - if (promise) { yield promise; } @@ -2104,10 +2113,6 @@ Zotero.ItemTreeView.prototype.rememberSelection = function (selection) { this._treebox.beginUpdateBatch(); } - // Use try/catch to work around NS_ERROR_UNEXPECTED from nsITreeSelection::toggleSelect(), - // apparently when the tree disappears before it's called (though I can't reproduce it): - // - // https://forums.zotero.org/discussion/69226/papers-become-invisible-in-the-middle-pane try { for (let i = 0; i < selection.length; i++) { if (this._rowMap[selection[i]] != null) { @@ -2133,6 +2138,10 @@ Zotero.ItemTreeView.prototype.rememberSelection = function (selection) { } } } + // Ignore NS_ERROR_UNEXPECTED from nsITreeSelection::toggleSelect(), apparently when the tree + // disappears before it's called (though I can't reproduce it): + // + // https://forums.zotero.org/discussion/69226/papers-become-invisible-in-the-middle-pane catch (e) { Zotero.logError(e); }