Fix collection collapse/expand issues

Fixes #722, Everything disappears
This commit is contained in:
Dan Stillman 2015-05-22 14:40:04 -04:00
parent 432d89af24
commit cf010d7748
2 changed files with 39 additions and 8 deletions

View File

@ -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);

View File

@ -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();