From ded8dca66840dbc07b046ba147733fa24a113d72 Mon Sep 17 00:00:00 2001 From: Dan Stillman Date: Sat, 31 May 2025 02:14:27 -0400 Subject: [PATCH] Properly clear previousData on save for primary data and item fields Closes #5297 --- .../content/zotero/xpcom/data/dataObject.js | 31 ++++++++++++++++++- 1 file changed, 30 insertions(+), 1 deletion(-) diff --git a/chrome/content/zotero/xpcom/data/dataObject.js b/chrome/content/zotero/xpcom/data/dataObject.js index 1cf96e083a..2a51a5e415 100644 --- a/chrome/content/zotero/xpcom/data/dataObject.js +++ b/chrome/content/zotero/xpcom/data/dataObject.js @@ -819,7 +819,36 @@ Zotero.DataObject.prototype.hasChanged = function() { Zotero.DataObject.prototype._clearChanged = function (dataType) { if (dataType) { delete this._changed[dataType]; - delete this._previousData[dataType]; + + // Unlike _changed, which has primary/item data under .primaryData/.itemData properties, + // _previousData has individual top-level fields regardless of category, so when clearing + // 'primaryData'/'itemData', check whether each stored field is a primary data or item field + // and clear if so + switch (dataType) { + case 'primaryData': + case 'itemData': + let toDelete = []; + for (let field of Object.keys(this._previousData)) { + if (dataType == 'primaryData') { + if (this.ObjectsClass.isPrimaryField(field)) { + toDelete.push(field); + } + } + else if (dataType == 'itemData') { + if (Zotero.ItemFields.getID(field)) { + toDelete.push(field); + } + } + } + for (let field of toDelete) { + delete this._previousData[field]; + } + break; + + default: + delete this._previousData[dataType]; + } + delete this._changedData[dataType]; } else {