Fix sorting of colored tags after Reactification
Regressed to alphabetic sorting instead of number-key sorting
This commit is contained in:
parent
2d71b13ce0
commit
b1fad505d7
2 changed files with 26 additions and 3 deletions
|
@ -112,12 +112,16 @@ Zotero.TagSelector = class TagSelectorContainer extends React.Component {
|
||||||
tags.push(Zotero.Tags.cleanData({ tag: x }))
|
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) {
|
tags.sort(function (a, b) {
|
||||||
let aColored = tagColors.has(a.tag),
|
let aColored = tagColors.get(a.tag);
|
||||||
bColored = tagColors.has(b.tag);
|
let bColored = tagColors.get(b.tag);
|
||||||
if (aColored && !bColored) return -1;
|
if (aColored && !bColored) return -1;
|
||||||
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);
|
return Zotero.getLocaleCollation().compareString(1, a.tag, b.tag);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
|
@ -46,6 +46,25 @@ describe("Tag Selector", function () {
|
||||||
win.close();
|
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 () {
|
it('should not display duplicate tags when automatic and manual tag with same name exists', async function () {
|
||||||
var collection = await createDataObject('collection');
|
var collection = await createDataObject('collection');
|
||||||
var item1 = createUnsavedDataObject('item', { collections: [collection.id] });
|
var item1 = createUnsavedDataObject('item', { collections: [collection.id] });
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue