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)
This commit is contained in:
Dan Stillman 2021-06-22 00:58:47 -04:00
parent 42b4b173f3
commit 91ebbc1bc9
2 changed files with 18 additions and 20 deletions
chrome/content/zotero/xpcom/data

View file

@ -3955,6 +3955,7 @@ Zotero.Item.prototype.setTags = function (tags) {
* *
* @param {String} name * @param {String} name
* @param {Number} [type=0] * @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) { Zotero.Item.prototype.addTag = function (name, type) {
type = type ? parseInt(type) : 0; type = type ? parseInt(type) : 0;
@ -4023,6 +4024,9 @@ Zotero.Item.prototype.replaceTag = function (oldTag, newTag) {
* Remove a tag from the item * Remove a tag from the item
* *
* A separate save() is required to update the database. * 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) { Zotero.Item.prototype.removeTag = function(tagName) {
this._requireData('tags'); this._requireData('tags');
@ -4030,9 +4034,10 @@ Zotero.Item.prototype.removeTag = function(tagName) {
var newTags = oldTags.filter(tagData => tagData.tag !== tagName); var newTags = oldTags.filter(tagData => tagData.tag !== tagName);
if (newTags.length == oldTags.length) { if (newTags.length == oldTags.length) {
Zotero.debug('Cannot remove missing tag ' + tagName + ' from item ' + this.libraryKey); Zotero.debug('Cannot remove missing tag ' + tagName + ' from item ' + this.libraryKey);
return; return false;
} }
this.setTags(newTags); this.setTags(newTags);
return true;
} }

View file

@ -736,29 +736,22 @@ Zotero.Tags = new function() {
// Color setting can exist without tag. If missing, we have to add the tag. // Color setting can exist without tag. If missing, we have to add the tag.
var tagID = this.getID(tagName); var tagID = this.getID(tagName);
return Zotero.DB.executeTransaction(function* () { return Zotero.DB.executeTransaction(async function () {
// Base our action on the first item. If it has the tag, // If all items already have the tag, remove it from all items
// remove the tag from all items. If it doesn't, add it to all. if (tagID && items.every(x => x.hasTag(tagName))) {
var firstItem = items[0]; for (let item of items) {
// Remove from all items if (item.removeTag(tagName)) {
if (tagID && firstItem.hasTag(tagName)) { await item.save();
for (let i=0; i<items.length; i++) { }
let item = items[i];
item.removeTag(tagName);
yield item.save({
skipDateModifiedUpdate: true
});
} }
Zotero.Prefs.set('purge.tags', true); Zotero.Prefs.set('purge.tags', true);
} }
// Add to all items // Otherwise add to all items
else { else {
for (let i=0; i<items.length; i++) { for (let item of items) {
let item = items[i]; if (item.addTag(tagName)) {
item.addTag(tagName); await item.save();
yield item.save({ }
skipDateModifiedUpdate: true
});
} }
} }
}.bind(this)); }.bind(this));