commit cf010d77484954f4907dad6af1af9986dc534660
parent 432d89af249110367969c2ed118f264428d859d6
Author: Dan Stillman <dstillman@zotero.org>
Date: Fri, 22 May 2015 14:40:04 -0400
Fix collection collapse/expand issues
Fixes #722, Everything disappears
Diffstat:
2 files changed, 39 insertions(+), 8 deletions(-)
diff --git a/chrome/content/zotero/xpcom/collectionTreeView.js b/chrome/content/zotero/xpcom/collectionTreeView.js
@@ -686,8 +686,7 @@ Zotero.CollectionTreeView.prototype.toggleOpenState = Zotero.Promise.coroutine(f
this.rowCount += count;
this._treebox.rowCountChanged(row + 1, count);
- // Toggle container open value
- this._rows[row][1] = true;
+ this._rows[row].isOpen = true;
this._treebox.invalidateRow(row);
this._refreshRowMap();
});
@@ -698,16 +697,15 @@ Zotero.CollectionTreeView.prototype._closeContainer = function (row) {
var count = 0;
var level = this.getLevel(row);
+ var nextRow = row + 1;
// Remove child rows
- while ((row + 1 < this._rows.length) && (this.getLevel(row + 1) > level)) {
- this._removeRow(row + 1);
+ while ((nextRow < this._rows.length) && (this.getLevel(nextRow) > level)) {
+ this._removeRow(nextRow);
count--;
}
- // Mark as removed from the end of the row's children
- this._treebox.rowCountChanged(row + 1 + Math.abs(count), count);
- this._rows[row][1] = false;
+ this._rows[row].isOpen = false;
this._treebox.invalidateRow(row);
this._refreshRowMap();
}
@@ -766,7 +764,7 @@ Zotero.CollectionTreeView.prototype.expandLibrary = Zotero.Promise.coroutine(fun
Zotero.CollectionTreeView.prototype.collapseLibrary = function (libraryID) {
var row = this._rowMap['L' + libraryID]
- if (!row) {
+ if (row === undefined) {
return false;
}
this._closeContainer(row);
diff --git a/test/tests/collectionTreeViewTest.js b/test/tests/collectionTreeViewTest.js
@@ -19,6 +19,39 @@ describe("Zotero.CollectionTreeView", function() {
assert.equal(collectionsView.getSelectedLibraryID(), Zotero.Libraries.userLibraryID);
}
+ describe("collapse/expand", function () {
+ it("should close and open My Library repeatedly", function* () {
+ var libraryID = Zotero.Libraries.userLibraryID;
+ var cv = collectionsView;
+ cv.selectLibrary(libraryID);
+ var row = cv.selection.currentIndex;
+
+ cv.collapseLibrary(libraryID);
+ var nextRow = cv.getRow(row + 1);
+ assert.equal(cv.selection.currentIndex, row);
+ assert.ok(nextRow.isSeparator());
+ assert.isFalse(cv.isContainerOpen(row));
+
+ yield cv.expandLibrary(libraryID);
+ nextRow = cv.getRow(row + 1);
+ assert.equal(cv.selection.currentIndex, row);
+ assert.ok(!nextRow.isSeparator());
+ assert.ok(cv.isContainerOpen(row));
+
+ cv.collapseLibrary(libraryID);
+ nextRow = cv.getRow(row + 1);
+ assert.equal(cv.selection.currentIndex, row);
+ assert.ok(nextRow.isSeparator());
+ assert.isFalse(cv.isContainerOpen(row));
+
+ yield cv.expandLibrary(libraryID);
+ nextRow = cv.getRow(row + 1);
+ assert.equal(cv.selection.currentIndex, row);
+ assert.ok(!nextRow.isSeparator());
+ assert.ok(cv.isContainerOpen(row));
+ })
+ })
+
describe("#notify()", function () {
it("should select a new collection", function* () {
resetSelection();