From 4fcf0c3c15c3c78f39d8ad4d872fc66c043c101e Mon Sep 17 00:00:00 2001 From: Dan Stillman Date: Sun, 13 Mar 2016 20:30:24 -0400 Subject: [PATCH] nsITreeSelection can be 0 incorrectly even if count is 0 --- chrome/content/zotero/xpcom/collectionTreeView.js | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/chrome/content/zotero/xpcom/collectionTreeView.js b/chrome/content/zotero/xpcom/collectionTreeView.js index 43de285b21..6c11d803b7 100644 --- a/chrome/content/zotero/xpcom/collectionTreeView.js +++ b/chrome/content/zotero/xpcom/collectionTreeView.js @@ -67,6 +67,9 @@ Zotero.CollectionTreeView.prototype.type = 'collection'; Object.defineProperty(Zotero.CollectionTreeView.prototype, "selectedTreeRow", { get: function () { + if (!this.selection || !this.selection.count) { + return false; + } return this.getRow(this.selection.currentIndex); } }); @@ -940,7 +943,7 @@ Zotero.CollectionTreeView.prototype.selectLibrary = Zotero.Promise.coroutine(fun } // Check if library is already selected - if (this.selection.currentIndex != -1) { + if (this.selection && this.selection.count && this.selection.currentIndex != -1) { var treeRow = this.getRow(this.selection.currentIndex); if (treeRow.isLibrary(true) && treeRow.ref.libraryID == libraryID) { this._treebox.ensureRowIsVisible(this.selection.currentIndex); @@ -972,7 +975,7 @@ Zotero.CollectionTreeView.prototype.selectSearch = function (id) { Zotero.CollectionTreeView.prototype.selectTrash = Zotero.Promise.coroutine(function* (libraryID) { // Check if trash is already selected - if (this.selection.currentIndex != -1) { + if (this.selection && this.selection.count && this.selection.currentIndex != -1) { let itemGroup = this.getRow(this.selection.currentIndex); if (itemGroup.isTrash() && itemGroup.ref.libraryID == libraryID) { this._treebox.ensureRowIsVisible(this.selection.currentIndex); @@ -1196,6 +1199,8 @@ Zotero.CollectionTreeView.prototype._expandRow = Zotero.Promise.coroutine(functi * Returns libraryID or FALSE if not a library */ Zotero.CollectionTreeView.prototype.getSelectedLibraryID = function() { + if (!this.selection || !this.selection.count || this.selection.currentIndex == -1) return false; + var treeRow = this.getRow(this.selection.currentIndex); return treeRow && treeRow.ref && treeRow.ref.libraryID !== undefined && treeRow.ref.libraryID;