From cadfca7475914f9c15e8ccca08fe8f7f445eaaba Mon Sep 17 00:00:00 2001 From: Dan Stillman Date: Sun, 9 Apr 2023 16:58:51 -0400 Subject: [PATCH] Set a default annotation color if not assigned https://forums.zotero.org/discussion/104249/sync-issue-on-ipados --- chrome/content/zotero/xpcom/annotations.js | 2 ++ chrome/content/zotero/xpcom/data/item.js | 2 +- test/tests/itemTest.js | 16 ++++++++++++++++ 3 files changed, 19 insertions(+), 1 deletion(-) diff --git a/chrome/content/zotero/xpcom/annotations.js b/chrome/content/zotero/xpcom/annotations.js index db83e4a028..cbe5621e35 100644 --- a/chrome/content/zotero/xpcom/annotations.js +++ b/chrome/content/zotero/xpcom/annotations.js @@ -33,6 +33,8 @@ Zotero.Annotations = new function () { Zotero.defineProperty(this, 'ANNOTATION_TYPE_IMAGE', { value: 3 }); Zotero.defineProperty(this, 'ANNOTATION_TYPE_INK', { value: 4 }); + Zotero.defineProperty(this, 'DEFAULT_COLOR', { value: '#ffd400' }); + Zotero.defineProperty(this, 'PROPS', { value: ['type', 'authorName', 'text', 'comment', 'color', 'pageLabel', 'sortIndex', 'position'], writable: false diff --git a/chrome/content/zotero/xpcom/data/item.js b/chrome/content/zotero/xpcom/data/item.js index 34154ba224..acf9d00865 100644 --- a/chrome/content/zotero/xpcom/data/item.js +++ b/chrome/content/zotero/xpcom/data/item.js @@ -1935,7 +1935,7 @@ Zotero.Item.prototype._saveData = Zotero.Promise.coroutine(function* (env) { authorName || null, text || null, comment || null, - color || null, + color || Zotero.Annotations.DEFAULT_COLOR, pageLabel || null, sortIndex, position, diff --git a/test/tests/itemTest.js b/test/tests/itemTest.js index a038f118b4..a04f9c07e3 100644 --- a/test/tests/itemTest.js +++ b/test/tests/itemTest.js @@ -1400,6 +1400,22 @@ describe("Zotero.Item", function () { assert.isFalse(annotation.hasChanged()); }); + it("should assign a default color", async function () { + var annotation = new Zotero.Item('annotation'); + annotation.parentID = attachment.id; + annotation.annotationType = 'highlight'; + annotation.annotationText = "This is highlighted text."; + annotation.annotationSortIndex = '00015|002431|00000'; + annotation.annotationPosition = JSON.stringify({ + pageIndex: 123, + rects: [ + [314.4, 412.8, 556.2, 609.6] + ] + }); + await annotation.saveTx(); + assert.equal(annotation.annotationColor, '#ffd400'); + }); + it("should save a note annotation", async function () { var annotation = new Zotero.Item('annotation'); annotation.parentID = attachment.id;