Fix #1038, Notes skip back to beginning if typing during auto-save

Set a unique id on the note editor at initialization and pass it along
to item.saveTx(). When notify() is called, if the save was triggered
from the current note field, don't do a refresh.

This does mean that the note field won't reflect changes (e.g.,
normalizations) made by the save process until the user clicks away and
back, which makes me a little uncomfortable. If we can find specific
cases where that occurs (paste?), we can reevaluate this approach.
This commit is contained in:
Dan Stillman 2016-07-17 15:08:52 -04:00
parent 69dec87aa6
commit 381fe38b89

View file

@ -144,6 +144,7 @@
<constructor>
<![CDATA[
this._instanceID = Zotero.Utilities.randomString();
this._notifierID = Zotero.Notifier.registerObserver(this, ['item'], 'noteeditor');
]]>
</constructor>
@ -158,6 +159,7 @@
<parameter name="event"/>
<parameter name="type"/>
<parameter name="ids"/>
<parameter name="extraData"/>
<body><![CDATA[
if (event != 'modify' || !this.item || !this.item.id) return;
for (let i = 0; i < ids.length; i++) {
@ -165,6 +167,10 @@
if (id != this.item.id) {
continue;
}
if (extraData && extraData[id] && extraData[id].noteEditorID == this._instanceID) {
//Zotero.debug("Skipping notification from current note field");
continue;
}
this.refresh();
break;
}
@ -243,7 +249,11 @@
if (this.item) {
let changed = this.item.setNote(noteField.value);
if (changed && this.saveOnEdit) {
yield this.item.saveTx();
yield this.item.saveTx({
notifierData: {
noteEditorID: this._instanceID
}
});
}
return;
}