Merge: Remove spacing from annotation regex, delete external annotation items
- `/Subtype` isn't necessarily preceded or followed by a space - Annotation items with `isExternal: true` are for display only and should be deleted on merge https://forums.zotero.org/discussion/105960/external-annotations-ignored-when-merging
This commit is contained in:
parent
a0cdf11096
commit
2aa34a6346
2 changed files with 18 additions and 4 deletions
|
@ -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);
|
||||
};
|
||||
|
||||
|
|
|
@ -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);
|
||||
|
|
Loading…
Reference in a new issue