Don't count missing annotation values as changed if empty string passed

Similar to 0d377a1c4a, this fixes an unnecessary annotation reload and
loss of unsaved typing on auto-sync immediately after an annotation is
created.
This commit is contained in:
Dan Stillman 2021-04-26 03:47:46 -04:00
parent 0d377a1c4a
commit 76d8818bed
3 changed files with 28 additions and 1 deletions

View file

@ -3671,6 +3671,14 @@ for (let name of ['type', 'text', 'comment', 'color', 'pageLabel', 'sortIndex',
set: function (value) {
this._requireData('annotation');
// Normalize values
if (typeof value == 'string') {
value = value.trim().normalize();
if (value === "") {
value = null;
}
}
if (this._getLatestField(field) === value) {
return;
}

View file

@ -942,7 +942,12 @@ async function createAnnotation(type, parentItem, options = {}) {
if (type == 'highlight') {
annotation.annotationText = Zotero.Utilities.randomString();
}
if (options.comment !== undefined) {
annotation.annotationComment = options.comment;
}
else {
annotation.annotationComment = Zotero.Utilities.randomString();
}
annotation.annotationColor = '#ffd400';
var page = Zotero.Utilities.rand(1, 100);
annotation.annotationPageLabel = `${page}`;

View file

@ -1333,6 +1333,20 @@ describe("Zotero.Item", function () {
});
});
describe("#annotationComment", function () {
it("should not mark object without comment as changed if empty string", async function () {
var annotation = await createAnnotation('highlight', attachment, { comment: "" });
annotation.annotationComment = "";
assert.isFalse(annotation.hasChanged());
});
it("should clear existing value when empty string is passed", async function () {
var annotation = await createAnnotation('highlight', attachment);
annotation.annotationComment = "";
assert.isTrue(annotation.hasChanged());
});
});
describe("#saveTx()", function () {
it("should save a highlight annotation", async function () {
var annotation = new Zotero.Item('annotation');