Fix item.clone() on annotation items
This commit is contained in:
parent
9eb4fdb9cd
commit
7889cd5d39
3 changed files with 26 additions and 1 deletions
|
@ -31,6 +31,11 @@ Zotero.Annotations = new function () {
|
|||
Zotero.defineProperty(this, 'ANNOTATION_TYPE_NOTE', { value: 2 });
|
||||
Zotero.defineProperty(this, 'ANNOTATION_TYPE_IMAGE', { value: 3 });
|
||||
|
||||
Zotero.defineProperty(this, 'PROPS', {
|
||||
value: ['type', 'text', 'comment', 'color', 'sortIndex', 'position'],
|
||||
writable: false
|
||||
});
|
||||
|
||||
|
||||
this.getCacheImagePath = function ({ libraryID, key }) {
|
||||
var file = this._getLibraryCacheDirectory(libraryID);
|
||||
|
|
|
@ -4481,7 +4481,7 @@ Zotero.Item.prototype.clone = function (libraryID, options = {}) {
|
|||
if (this.isRegularItem()) {
|
||||
newItem.setCreators(this.getCreators());
|
||||
}
|
||||
else {
|
||||
else if (this.isNote() || this.isAttachment()) {
|
||||
newItem.setNote(this.getNote());
|
||||
if (sameLibrary) {
|
||||
var parent = this.parentKey;
|
||||
|
@ -4501,6 +4501,13 @@ Zotero.Item.prototype.clone = function (libraryID, options = {}) {
|
|||
}
|
||||
}
|
||||
}
|
||||
else if (this.isAnnotation()) {
|
||||
let props = Zotero.Annotations.PROPS;
|
||||
for (let prop of props) {
|
||||
let fullProp = 'annotation' + Zotero.Utilities.capitalize(prop);
|
||||
newItem[fullProp] = this[fullProp];
|
||||
}
|
||||
}
|
||||
|
||||
if (!options.skipTags) {
|
||||
newItem.setTags(this.getTags());
|
||||
|
|
|
@ -1729,6 +1729,19 @@ describe("Zotero.Item", function () {
|
|||
var newItem = item.clone();
|
||||
assert.isEmpty(Object.keys(newItem.toJSON().relations));
|
||||
});
|
||||
|
||||
it("should clone an annotation item", async function () {
|
||||
var attachment = await importFileAttachment('test.pdf');
|
||||
var annotation = await createAnnotation('highlight', attachment);
|
||||
var newAnnotation = annotation.clone();
|
||||
|
||||
var fields = Object.keys(annotation.toJSON())
|
||||
.filter(field => field.startsWith('annotation'));
|
||||
assert.isAbove(fields.length, 0);
|
||||
for (let field of fields) {
|
||||
assert.equal(annotation[field], newAnnotation[field]);
|
||||
}
|
||||
});
|
||||
})
|
||||
|
||||
describe("#moveToLibrary()", function () {
|
||||
|
|
Loading…
Reference in a new issue