Fix renaming and clearing of colored tags
This commit is contained in:
parent
fe186333be
commit
3a8357cb95
4 changed files with 65 additions and 6 deletions
|
@ -772,8 +772,16 @@
|
||||||
if (!color) {
|
if (!color) {
|
||||||
throw new Error("Can't rename missing tag");
|
throw new Error("Can't rename missing tag");
|
||||||
}
|
}
|
||||||
yield Zotero.Tags.setColor(this.libraryID, oldName, false);
|
|
||||||
yield Zotero.Tags.setColor(this.libraryID, newName, color);
|
yield Zotero.DB.executeTransaction(function* () {
|
||||||
|
yield Zotero.Tags.setColor(this.libraryID, oldName, false);
|
||||||
|
yield Zotero.Tags.setColor(
|
||||||
|
this.libraryID,
|
||||||
|
newName.value,
|
||||||
|
color.color,
|
||||||
|
color.position
|
||||||
|
);
|
||||||
|
}.bind(this));
|
||||||
}
|
}
|
||||||
|
|
||||||
if (wasSelected) {
|
if (wasSelected) {
|
||||||
|
|
|
@ -501,7 +501,17 @@ Zotero.Tags = new function() {
|
||||||
|
|
||||||
var tagColors = Zotero.SyncedSettings.get(libraryID, 'tagColors');
|
var tagColors = Zotero.SyncedSettings.get(libraryID, 'tagColors');
|
||||||
|
|
||||||
tagColors = tagColors || [];
|
// Sanitize -- shouldn't be necessary, but just in case a bad value makes it into the setting
|
||||||
|
if (!Array.isArray(tagColors)) {
|
||||||
|
tagColors = [];
|
||||||
|
}
|
||||||
|
tagColors = tagColors.filter(color => {
|
||||||
|
if (typeof color != 'object' || typeof color.name != 'string' || typeof color.color != 'string') {
|
||||||
|
Zotero.logError("Skipping invalid colored tag: " + JSON.stringify(color));
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
});
|
||||||
|
|
||||||
_libraryColors[libraryID] = tagColors;
|
_libraryColors[libraryID] = tagColors;
|
||||||
_libraryColorsByName[libraryID] = new Map;
|
_libraryColorsByName[libraryID] = new Map;
|
||||||
|
@ -539,7 +549,8 @@ Zotero.Tags = new function() {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
tagColors = tagColors.filter(val => val.name != name);
|
_libraryColors[libraryID] = tagColors = tagColors.filter(val => val.name != name);
|
||||||
|
_libraryColorsByName[libraryID].delete(name);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
// Get current position if present
|
// Get current position if present
|
||||||
|
|
|
@ -356,7 +356,32 @@ describe("Tag Selector", function () {
|
||||||
|
|
||||||
var tags = getRegularTags();
|
var tags = getRegularTags();
|
||||||
assert.include(tags, newTag);
|
assert.include(tags, newTag);
|
||||||
})
|
});
|
||||||
|
|
||||||
|
it("should rename a non-matching colored tag and update the tag selector", function* () {
|
||||||
|
yield selectLibrary(win);
|
||||||
|
|
||||||
|
var oldTag = Zotero.Utilities.randomString();
|
||||||
|
var newTag = Zotero.Utilities.randomString();
|
||||||
|
|
||||||
|
var libraryID = Zotero.Libraries.userLibraryID;
|
||||||
|
var promise = waitForTagSelector(win);
|
||||||
|
yield Zotero.Tags.setColor(libraryID, oldTag, "#F3F3F3");
|
||||||
|
yield promise;
|
||||||
|
|
||||||
|
var tagSelector = doc.getElementById('zotero-tag-selector');
|
||||||
|
promise = waitForTagSelector(win);
|
||||||
|
var promptPromise = waitForWindow("chrome://global/content/commonDialog.xul", function (dialog) {
|
||||||
|
dialog.document.getElementById('loginTextbox').value = newTag;
|
||||||
|
dialog.document.documentElement.acceptDialog();
|
||||||
|
})
|
||||||
|
yield tagSelector.rename(oldTag);
|
||||||
|
yield promise;
|
||||||
|
|
||||||
|
var tags = getColoredTags();
|
||||||
|
assert.notInclude(tags, oldTag);
|
||||||
|
assert.include(tags, newTag);
|
||||||
|
});
|
||||||
})
|
})
|
||||||
|
|
||||||
describe("#_openColorPickerWindow()", function () {
|
describe("#_openColorPickerWindow()", function () {
|
||||||
|
|
|
@ -69,7 +69,7 @@ describe("Zotero.Tags", function () {
|
||||||
describe("#setColor()", function () {
|
describe("#setColor()", function () {
|
||||||
var libraryID;
|
var libraryID;
|
||||||
|
|
||||||
before(function* () {
|
beforeEach(function* () {
|
||||||
libraryID = Zotero.Libraries.userLibraryID;
|
libraryID = Zotero.Libraries.userLibraryID;
|
||||||
|
|
||||||
// Clear library tag colors
|
// Clear library tag colors
|
||||||
|
@ -97,5 +97,20 @@ describe("Zotero.Tags", function () {
|
||||||
assert.lengthOf(o, 2);
|
assert.lengthOf(o, 2);
|
||||||
assert.sameMembers(o.map(c => c.color), [aColor, bColor]);
|
assert.sameMembers(o.map(c => c.color), [aColor, bColor]);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it("should clear color for a tag", function* () {
|
||||||
|
var aColor = '#ABCDEF';
|
||||||
|
yield Zotero.Tags.setColor(libraryID, "A", aColor);
|
||||||
|
var o = Zotero.Tags.getColor(libraryID, "A")
|
||||||
|
assert.equal(o.color, aColor);
|
||||||
|
assert.equal(o.position, 0);
|
||||||
|
|
||||||
|
yield Zotero.Tags.setColor(libraryID, "A", false);
|
||||||
|
assert.equal(Zotero.Tags.getColors(libraryID).size, 0);
|
||||||
|
assert.isFalse(Zotero.Tags.getColor(libraryID, "A"));
|
||||||
|
|
||||||
|
var o = Zotero.SyncedSettings.get(libraryID, 'tagColors');
|
||||||
|
assert.isNull(o);
|
||||||
|
});
|
||||||
});
|
});
|
||||||
})
|
})
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue