From 15f6a81181dd696349447cb542cec56ff1d621f4 Mon Sep 17 00:00:00 2001 From: Dan Stillman Date: Wed, 30 Sep 2026 11:45:36 -0400 Subject: [PATCH] Refresh tag selector when a tag's type changes between views Switching to a view that has the same tags but with different types (manual vs. automatic) kept the previous list, so with "Show Automatic" off a tag could show or hide incorrectly. --- .../containers/tagSelectorContainer.jsx | 4 +-- test/tests/tagSelectorTest.js | 33 +++++++++++++++++++ 2 files changed, 35 insertions(+), 2 deletions(-) diff --git a/chrome/content/zotero/containers/tagSelectorContainer.jsx b/chrome/content/zotero/containers/tagSelectorContainer.jsx index bb5b59147a..82c8ae51f4 100644 --- a/chrome/content/zotero/containers/tagSelectorContainer.jsx +++ b/chrome/content/zotero/containers/tagSelectorContainer.jsx @@ -416,10 +416,10 @@ Zotero.TagSelector = class TagSelectorContainer extends React.PureComponent { // If tags haven't changed, return previous array without sorting again if (this.state.tags.length == tags.length) { - let prevTags = new Set(this.state.tags.map(tag => tag.tag)); + let prevTags = new Set(this.state.tags.map(tag => tag.type + ':' + tag.tag)); let same = true; for (let tag of tags) { - if (!prevTags.has(tag.tag)) { + if (!prevTags.has(tag.type + ':' + tag.tag)) { same = false; break; } diff --git a/test/tests/tagSelectorTest.js b/test/tests/tagSelectorTest.js index d4f4d55e99..f5d5b15568 100644 --- a/test/tests/tagSelectorTest.js +++ b/test/tests/tagSelectorTest.js @@ -127,6 +127,39 @@ describe("Tag Selector", function () { } }); + it("should hide a tag that's only automatic in the new view when automatic tags are hidden", async function () { + var collection1 = await createDataObject('collection'); + var collection2 = await createDataObject('collection'); + var item1 = createUnsavedDataObject('item', { collections: [collection1.id] }); + item1.setTags(["A", "B"]); + var item2 = createUnsavedDataObject('item', { collections: [collection2.id] }); + item2.setTags([{ tag: "A", type: 1 }, "B"]); + await Zotero.DB.executeTransaction(async function () { + await item1.save(); + await item2.save(); + }); + + tagSelector.toggleShowAutomatic(false); + try { + await select(win, collection1); + await waitForCallback(() => getRegularTags().length == 2); + + var spy = sinon.spy(tagSelector, 'onItemViewChanged'); + try { + await select(win, collection2); + await waitForCallback(() => spy.called); + await spy.lastCall.returnValue; + } + finally { + spy.restore(); + } + assert.sameMembers(getRegularTags(), ['B']); + } + finally { + tagSelector.toggleShowAutomatic(true); + } + }); + it("should show tags from annotations for attachments in scope", async function () { var collection = await createDataObject('collection'); await select(win, collection);