Add item sanity check to note editor
When refreshing the note editor, store the associated itemID on the textbox, and check it when saving to make sure it's for the expected note. This might prevent weird situations (which I can't reproduce, but there was a report in the forums [1]) where something goes wrong and the note doesn't refresh when selecting a new item, and then one note's content is saved over another's. [1] https://forums.zotero.org/discussion/65708/
This commit is contained in:
parent
c4411e1ad3
commit
d9fbccca67
2 changed files with 19 additions and 1 deletions
|
@ -201,10 +201,13 @@
|
|||
|
||||
//var scrollPos = textbox.inputField.scrollTop;
|
||||
if (this.item) {
|
||||
// For sanity check in save()
|
||||
textbox.setAttribute('itemID', this.item.id);
|
||||
textbox.value = this.item.getNote();
|
||||
}
|
||||
else {
|
||||
textbox.value = '';
|
||||
textbox.removeAttribute('itemID');
|
||||
}
|
||||
//textbox.inputField.scrollTop = scrollPos;
|
||||
|
||||
|
@ -251,6 +254,15 @@
|
|||
// Update note
|
||||
var noteField = this._id('noteField');
|
||||
if (this.item) {
|
||||
// If note field doesn't match item, abort save and run error handler
|
||||
if (noteField.getAttribute('itemID') != this.item.id) {
|
||||
if (this.hasAttribute('onerror')) {
|
||||
let fn = new Function("", this.getAttribute('onerror'));
|
||||
fn.call(this)
|
||||
}
|
||||
throw new Error("Note field doesn't match current item");
|
||||
}
|
||||
|
||||
let changed = this.item.setNote(noteField.value);
|
||||
if (changed && this.saveOnEdit) {
|
||||
this.noteField.changed = false;
|
||||
|
|
|
@ -107,7 +107,13 @@
|
|||
|
||||
<!-- Note item -->
|
||||
<groupbox id="zotero-view-note" flex="1">
|
||||
<zoteronoteeditor id="zotero-note-editor" flex="1" notitle="1" previousfocus="zotero-items-tree"/>
|
||||
<!--
|
||||
'onerror' handler crashes the app on a save error to prevent typing in notes
|
||||
while they're not being saved
|
||||
-->
|
||||
<zoteronoteeditor id="zotero-note-editor" flex="1" notitle="1"
|
||||
previousfocus="zotero-items-tree"
|
||||
onerror="ZoteroPane.displayErrorMessage()"/>
|
||||
<button id="zotero-view-note-button" label="&zotero.notes.separate;" oncommand="ZoteroPane_Local.openNoteWindow(this.getAttribute('noteID')); if(this.hasAttribute('sourceID')) ZoteroPane_Local.selectItem(this.getAttribute('sourceID'));"/>
|
||||
</groupbox>
|
||||
|
||||
|
|
Loading…
Reference in a new issue