From 79950ecfe548c846f14703d73a88f8f80404a036 Mon Sep 17 00:00:00 2001 From: Dan Stillman Date: Tue, 23 Feb 2021 05:43:03 -0500 Subject: [PATCH] Exclude annotations from library export We'll want to support this eventually, but for now they would just break translation. --- .../xpcom/translation/translate_item.js | 10 +++++++++- test/tests/translateTest.js | 19 +++++++++++++++++++ 2 files changed, 28 insertions(+), 1 deletion(-) diff --git a/chrome/content/zotero/xpcom/translation/translate_item.js b/chrome/content/zotero/xpcom/translation/translate_item.js index 92bad615a1..9e625fb5d7 100644 --- a/chrome/content/zotero/xpcom/translation/translate_item.js +++ b/chrome/content/zotero/xpcom/translation/translate_item.js @@ -1038,7 +1038,15 @@ Zotero.Translate.ItemGetter.prototype = { }, "setAll": Zotero.Promise.coroutine(function* (libraryID, getChildCollections) { - this._itemsLeft = yield Zotero.Items.getAll(libraryID, true); + this._itemsLeft = (yield Zotero.Items.getAll(libraryID, true)) + .filter((item) => { + // Don't export annotations + switch (item.itemType) { + case 'annotation': + return false; + } + return true; + }); if(getChildCollections) { this._collectionsLeft = Zotero.Collections.getByLibrary(libraryID); diff --git a/test/tests/translateTest.js b/test/tests/translateTest.js index 605a48ff09..936d30afa4 100644 --- a/test/tests/translateTest.js +++ b/test/tests/translateTest.js @@ -2121,6 +2121,25 @@ describe("Zotero.Translate.ItemGetter", function() { }); }); + describe("#setAll()", function () { + it("should exclude annotations", async function () { + var attachment = await importFileAttachment('test.pdf'); + var annotation = await createAnnotation('highlight', attachment); + + var getter = new Zotero.Translate.ItemGetter(); + await getter.setAll(attachment.libraryID, false); + + var item; + while (item = getter.nextItem()) { + if (item.itemType == 'annotation') { + assert.fail("Annotation item should not be returned from nextItem()"); + break; + } + } + assert.equal(getter.numItems, 1); + }); + }); + describe("#_attachmentToArray()", function () { it("should handle missing attachment files", function* () { var item = yield importFileAttachment('test.png');