diff --git a/chrome/content/zotero/xpcom/itemTreeView.js b/chrome/content/zotero/xpcom/itemTreeView.js index 8ac2938a74..e7047e974c 100644 --- 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 index 05b56ad01c..f68eb65f94 100644 --- 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 index 57c267f3c7..14c17f546d 100644 --- 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 index 9a030edec2..13b286262f 100644 --- 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;