Skip to content

Commit

Permalink
Add item sanity check to note editor
Browse files Browse the repository at this point in the history
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/
  • Loading branch information
dstillman committed May 18, 2017
1 parent c4411e1 commit d9fbccc
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 1 deletion.
12 changes: 12 additions & 0 deletions chrome/content/zotero/bindings/noteeditor.xml
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down
8 changes: 7 additions & 1 deletion chrome/content/zotero/itemPane.xul
Expand Up @@ -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>

Expand Down

0 comments on commit d9fbccc

Please sign in to comment.