diff --git a/chrome/content/zotero/containers/tagSelector.jsx b/chrome/content/zotero/containers/tagSelector.jsx index 858f8ed1fb..fd371a28b9 100644 --- a/chrome/content/zotero/containers/tagSelector.jsx +++ b/chrome/content/zotero/containers/tagSelector.jsx @@ -112,12 +112,16 @@ Zotero.TagSelector = class TagSelectorContainer extends React.Component { tags.push(Zotero.Tags.cleanData({ tag: x })) ); - // Sort by name + // Sort by name (except for colored tags, which sort by assigned number key) tags.sort(function (a, b) { - let aColored = tagColors.has(a.tag), - bColored = tagColors.has(b.tag); + let aColored = tagColors.get(a.tag); + let bColored = tagColors.get(b.tag); if (aColored && !bColored) return -1; if (!aColored && bColored) return 1; + if (aColored && bColored) { + return aColored.position - bColored.position; + } + return Zotero.getLocaleCollation().compareString(1, a.tag, b.tag); }); diff --git a/test/tests/tagSelectorTest.js b/test/tests/tagSelectorTest.js index 454b48ba31..2e7e773b37 100644 --- a/test/tests/tagSelectorTest.js +++ b/test/tests/tagSelectorTest.js @@ -46,6 +46,25 @@ describe("Tag Selector", function () { win.close(); }); + it("should sort colored tags by assigned number key", async function () { + var libraryID = Zotero.Libraries.userLibraryID; + var collection = await createDataObject('collection'); + + await Zotero.Tags.setColor(libraryID, "B", '#AAAAAA', 1); + await Zotero.Tags.setColor(libraryID, "A", '#BBBBBB', 2); + await Zotero.Tags.setColor(libraryID, "C", '#CCCCCC', 3); + + var item = createUnsavedDataObject('item', { collections: [collection.id] }); + var item = createUnsavedDataObject('item'); + await item.setTags(["A", "B"]); + var promise = waitForTagSelector(win); + await item.saveTx(); + await promise; + + var tags = getColoredTags(); + assert.sameOrderedMembers(tags, ['B', 'A', 'C']); + }); + it('should not display duplicate tags when automatic and manual tag with same name exists', async function () { var collection = await createDataObject('collection'); var item1 = createUnsavedDataObject('item', { collections: [collection.id] });