From d9fbccca67fe2b98a36b3f303f8404b4a569bac0 Mon Sep 17 00:00:00 2001 From: Dan Stillman Date: Wed, 17 May 2017 21:25:45 -0400 Subject: [PATCH] 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/ --- chrome/content/zotero/bindings/noteeditor.xml | 12 ++++++++++++ chrome/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 index e40906b50..f06be6d7b 100644 --- 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 index ff3baa295..3609daa1b 100644 --- a/chrome/content/zotero/itemPane.xul +++ b/chrome/content/zotero/itemPane.xul @@ -107,7 +107,13 @@ - + +