commit edb53c31df34307cf58849ed6224a0296e27a27c
parent 820755e152117cffb9b7202ecbb7f3bb9780f5b9
Author: Dan Stillman <dstillman@zotero.org>
Date: Fri, 24 Mar 2017 05:20:19 -0400
Fix updating of tag selector after filtering the middle pane
Adds a 'refresh' event to libraryTreeView
Diffstat:
4 files changed, 51 insertions(+), 2 deletions(-)
diff --git a/chrome/content/zotero/xpcom/itemTreeView.js b/chrome/content/zotero/xpcom/itemTreeView.js
@@ -426,6 +426,8 @@ Zotero.ItemTreeView.prototype.refresh = Zotero.serial(Zotero.Promise.coroutine(f
this.selection.selectEventsSuppressed = false;
}
+ yield this.runListeners('refresh');
+
setTimeout(function () {
resolve();
});
diff --git a/chrome/content/zotero/xpcom/libraryTreeView.js b/chrome/content/zotero/xpcom/libraryTreeView.js
@@ -33,7 +33,7 @@ Zotero.LibraryTreeView = function () {
Zotero.debug("Creating " + this.type + "s view with id " + this.id);
//
- // Create .on(Load|Select).addListener() methods
+ // Create .on(Load|Select|Refresh).addListener() methods
//
var _createEventBinding = function (event, alwaysOnce) {
return alwaysOnce
@@ -47,6 +47,7 @@ Zotero.LibraryTreeView = function () {
this.onLoad = _createEventBinding('load', true);
this.onSelect = _createEventBinding('select');
+ this.onRefresh = _createEventBinding('refresh');
};
Zotero.LibraryTreeView.prototype = {
diff --git a/chrome/content/zotero/zoteroPane.js b/chrome/content/zotero/zoteroPane.js
@@ -1238,7 +1238,7 @@ var ZoteroPane = new function()
Zotero.Prefs.clear('lastViewedFolder');
ZoteroPane_Local.displayErrorMessage();
};
- this.itemsView.onLoad.addListener(() => this.setTagScope());
+ this.itemsView.onRefresh.addListener(() => this.setTagScope());
if (this.tagSelectorShown()) {
let tagSelector = document.getElementById('zotero-tag-selector')
let handler = function () {
diff --git a/test/tests/tagSelectorTest.js b/test/tests/tagSelectorTest.js
@@ -53,6 +53,52 @@ describe("Tag Selector", function () {
win.close();
});
+ describe("#refresh()", function () {
+ it("should remove tags not on matching items on tag click", function* () {
+ var collection = yield createDataObject('collection');
+ var item1 = createUnsavedDataObject('item', { collections: [collection.id] });
+ item1.setTags([
+ {
+ tag: "A"
+ }
+ ]);
+ var item2 = createUnsavedDataObject('item', { collections: [collection.id] });
+ item2.setTags([
+ {
+ tag: "A"
+ },
+ {
+ tag: "B"
+ }
+ ]);
+ var item3 = createUnsavedDataObject('item', { collections: [collection.id] });
+ item3.setTags([
+ {
+ tag: "C"
+ }
+ ]);
+ var promise = waitForTagSelector(win);
+ yield Zotero.DB.executeTransaction(function* () {
+ yield item1.save();
+ yield item2.save();
+ yield item3.save();
+ });
+ yield promise;
+
+ var tagSelector = doc.getElementById('zotero-tag-selector');
+ var buttons = tagSelector.id('tags-box').getElementsByTagName('button');
+ var spy = sinon.spy(win.ZoteroPane, "updateTagFilter");
+ buttons[0].click();
+
+ yield spy.returnValues[0];
+
+ spy.restore();
+
+ var tags = getRegularTags();
+ assert.sameMembers(tags, ['A', 'B']);
+ });
+ });
+
describe("#notify()", function () {
it("should add a tag when added to an item in the library root", function* () {
var promise, tagSelector;