diff --git a/chrome/content/zotero/xpcom/data/item.js b/chrome/content/zotero/xpcom/data/item.js index 9cb769c2fe..0d29b2959e 100644 --- a/chrome/content/zotero/xpcom/data/item.js +++ b/chrome/content/zotero/xpcom/data/item.js @@ -3974,7 +3974,7 @@ Zotero.Item.prototype.hasEmbeddedAnnotations = async function () { let contents = await Zotero.File.getContentsAsync(path); // Check for "markup" annotations per the PDF spec // https://opensource.adobe.com/dc-acrobat-sdk-docs/pdfstandards/PDF32000_2008.pdf, p. 390 - let re = /\s\/Subtype\s+\/(Text|FreeText|Line|Square|Circle|Polygon|PolyLine|Highlight|Underline|Squiggly|StrikeOut|Stamp|Caret|Ink|FileAttachment|Sound|Redact)\s/; + let re = /\/Subtype\s*\/(Text|FreeText|Line|Square|Circle|Polygon|PolyLine|Highlight|Underline|Squiggly|StrikeOut|Stamp|Caret|Ink|FileAttachment|Sound|Redact)/; return re.test(contents); }; diff --git a/chrome/content/zotero/xpcom/data/items.js b/chrome/content/zotero/xpcom/data/items.js index 3bb182f96b..8bb34febd8 100644 --- a/chrome/content/zotero/xpcom/data/items.js +++ b/chrome/content/zotero/xpcom/data/items.js @@ -956,11 +956,24 @@ Zotero.Items = function() { if (fromItem.isFileAttachment()) { let annotations = fromItem.getAnnotations(includeTrashed); for (let annotation of annotations) { + if (annotation.annotationIsExternal) { + await annotation.erase(); + continue; + } annotation.parentItemID = toItem.id; await annotation.save(); } } + if (toItem.isFileAttachment()) { + let annotations = toItem.getAnnotations(includeTrashed); + for (let annotation of annotations) { + if (annotation.annotationIsExternal) { + await annotation.erase(); + } + } + } + // TODO: Other things as necessary }; @@ -1129,16 +1142,15 @@ Zotero.Items = function() { } // Check whether master and other have embedded annotations - // Master yes, other yes -> keep both - // Master yes, other no -> keep master - // Master no, other yes -> keep other if (await otherAttachment.hasEmbeddedAnnotations()) { + // Other yes, master yes -> keep both if (await masterAttachment.hasEmbeddedAnnotations()) { Zotero.debug(`Master attachment ${masterAttachment.key} matches ${otherAttachment.key}, ` + 'but both have embedded annotations - keeping both'); otherAttachment.parentItemID = item.id; await otherAttachment.save(); } + // Other yes, master no -> keep other else { Zotero.debug(`Master attachment ${masterAttachment.key} matches ${otherAttachment.key}, ` + 'but other has embedded annotations - merging into other'); @@ -1148,6 +1160,8 @@ Zotero.Items = function() { } continue; } + // Other no, master yes -> keep master + // Other no, master no -> keep master Zotero.debug(`Master attachment ${masterAttachment.key} matches ${otherAttachment.key} - merging into master`); await doMerge(otherAttachment, masterAttachment);