www

Unnamed repository; edit this file 'description' to name the repository.
Log | Files | Refs | Submodules | README | LICENSE

commit d9fbccca67fe2b98a36b3f303f8404b4a569bac0
parent c4411e1ad3edb644e863c1dc857690361ec09177
Author: Dan Stillman <dstillman@zotero.org>
Date:   Wed, 17 May 2017 21:25:45 -0400

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/

Diffstat:
Mchrome/content/zotero/bindings/noteeditor.xml | 12++++++++++++
Mchrome/content/zotero/itemPane.xul | 8+++++++-
2 files changed, 19 insertions(+), 1 deletion(-)

diff --git a/chrome/content/zotero/bindings/noteeditor.xml b/chrome/content/zotero/bindings/noteeditor.xml @@ -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; diff --git a/chrome/content/zotero/itemPane.xul b/chrome/content/zotero/itemPane.xul @@ -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>