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:
parent
0d377a1c4a
commit
76d8818bed
3 changed files with 28 additions and 1 deletions
|
@ -3671,6 +3671,14 @@ for (let name of ['type', 'text', 'comment', 'color', 'pageLabel', 'sortIndex',
|
||||||
set: function (value) {
|
set: function (value) {
|
||||||
this._requireData('annotation');
|
this._requireData('annotation');
|
||||||
|
|
||||||
|
// Normalize values
|
||||||
|
if (typeof value == 'string') {
|
||||||
|
value = value.trim().normalize();
|
||||||
|
if (value === "") {
|
||||||
|
value = null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if (this._getLatestField(field) === value) {
|
if (this._getLatestField(field) === value) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
|
@ -942,7 +942,12 @@ async function createAnnotation(type, parentItem, options = {}) {
|
||||||
if (type == 'highlight') {
|
if (type == 'highlight') {
|
||||||
annotation.annotationText = Zotero.Utilities.randomString();
|
annotation.annotationText = Zotero.Utilities.randomString();
|
||||||
}
|
}
|
||||||
annotation.annotationComment = Zotero.Utilities.randomString();
|
if (options.comment !== undefined) {
|
||||||
|
annotation.annotationComment = options.comment;
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
annotation.annotationComment = Zotero.Utilities.randomString();
|
||||||
|
}
|
||||||
annotation.annotationColor = '#ffd400';
|
annotation.annotationColor = '#ffd400';
|
||||||
var page = Zotero.Utilities.rand(1, 100);
|
var page = Zotero.Utilities.rand(1, 100);
|
||||||
annotation.annotationPageLabel = `${page}`;
|
annotation.annotationPageLabel = `${page}`;
|
||||||
|
|
|
@ -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 () {
|
describe("#saveTx()", function () {
|
||||||
it("should save a highlight annotation", async function () {
|
it("should save a highlight annotation", async function () {
|
||||||
var annotation = new Zotero.Item('annotation');
|
var annotation = new Zotero.Item('annotation');
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue