From 91ebbc1bc9c6f599f7a3f53f5790a2909cad00df Mon Sep 17 00:00:00 2001 From: Dan Stillman Date: Tue, 22 Jun 2021 00:58:47 -0400 Subject: [PATCH] Changes to colored tag toggling via keyboard - Update Date Modified when toggling tags via keyboard (https://forums.zotero.org/discussion/90371/bug-toggling-a-colored-tag-with-number-keys-doesnt-update-date-modified) - If any selected items don't have the tag, add it to all items, instead of deciding based on the first item (https://forums.zotero.org/discussion/79900/minor-issue-related-to-colored-tags) --- chrome/content/zotero/xpcom/data/item.js | 7 +++++- chrome/content/zotero/xpcom/data/tags.js | 31 +++++++++--------------- 2 files changed, 18 insertions(+), 20 deletions(-) diff --git a/chrome/content/zotero/xpcom/data/item.js b/chrome/content/zotero/xpcom/data/item.js index 3c8d35bdf0..984771b1cd 100644 --- a/chrome/content/zotero/xpcom/data/item.js +++ b/chrome/content/zotero/xpcom/data/item.js @@ -3955,6 +3955,7 @@ Zotero.Item.prototype.setTags = function (tags) { * * @param {String} name * @param {Number} [type=0] + * @return {Boolean} - True if the tag was added; false if the item already had the tag */ Zotero.Item.prototype.addTag = function (name, type) { type = type ? parseInt(type) : 0; @@ -4023,6 +4024,9 @@ Zotero.Item.prototype.replaceTag = function (oldTag, newTag) { * Remove a tag from the item * * A separate save() is required to update the database. + * + * @param {String} tagName + * @return {Boolean} - True if the tag was removed; false if the item didn't have the tag */ Zotero.Item.prototype.removeTag = function(tagName) { this._requireData('tags'); @@ -4030,9 +4034,10 @@ Zotero.Item.prototype.removeTag = function(tagName) { var newTags = oldTags.filter(tagData => tagData.tag !== tagName); if (newTags.length == oldTags.length) { Zotero.debug('Cannot remove missing tag ' + tagName + ' from item ' + this.libraryKey); - return; + return false; } this.setTags(newTags); + return true; } diff --git a/chrome/content/zotero/xpcom/data/tags.js b/chrome/content/zotero/xpcom/data/tags.js index 028d32bc85..1324c44407 100644 --- a/chrome/content/zotero/xpcom/data/tags.js +++ b/chrome/content/zotero/xpcom/data/tags.js @@ -736,29 +736,22 @@ Zotero.Tags = new function() { // Color setting can exist without tag. If missing, we have to add the tag. var tagID = this.getID(tagName); - return Zotero.DB.executeTransaction(function* () { - // Base our action on the first item. If it has the tag, - // remove the tag from all items. If it doesn't, add it to all. - var firstItem = items[0]; - // Remove from all items - if (tagID && firstItem.hasTag(tagName)) { - for (let i=0; i x.hasTag(tagName))) { + for (let item of items) { + if (item.removeTag(tagName)) { + await item.save(); + } } Zotero.Prefs.set('purge.tags', true); } - // Add to all items + // Otherwise add to all items else { - for (let i=0; i