From 4449da7e91c142eadef888096131f0880ef01419 Mon Sep 17 00:00:00 2001 From: Dan Stillman Date: Sun, 17 Jul 2016 14:55:02 -0400 Subject: [PATCH] Tweak note field auto-save triggering This avoids unnecessary timeout calls and fixes a problem where typing in a newly initialized note doesn't save it until the first blur(). --- chrome/content/zotero/bindings/noteeditor.xml | 5 ----- .../zotero/bindings/styled-textbox.xml | 19 +++++++++---------- 2 files changed, 9 insertions(+), 15 deletions(-) diff --git a/chrome/content/zotero/bindings/noteeditor.xml b/chrome/content/zotero/bindings/noteeditor.xml index 485c47aed..987c3d1b0 100644 --- a/chrome/content/zotero/bindings/noteeditor.xml +++ b/chrome/content/zotero/bindings/noteeditor.xml @@ -241,11 +241,6 @@ // Update note var noteField = this._id('noteField'); if (this.item) { - if (!noteField.changed) { - Zotero.debug("Note hasn't been modified -- not saving"); - return; - } - let changed = this.item.setNote(noteField.value); if (changed && this.saveOnEdit) { yield this.item.saveTx(); diff --git a/chrome/content/zotero/bindings/styled-textbox.xml b/chrome/content/zotero/bindings/styled-textbox.xml index 32b0abe08..4c0f6709d 100644 --- a/chrome/content/zotero/bindings/styled-textbox.xml +++ b/chrome/content/zotero/bindings/styled-textbox.xml @@ -400,6 +400,7 @@ case 'keypress': // Ignore keypresses that don't change // any text + //Zotero.debug(event.which); if (!event.which && event.keyCode != event.DOM_VK_DELETE && event.keyCode != event.DOM_VK_BACK_SPACE) { @@ -426,18 +427,16 @@ clearTimeout(self._timer); } - if (event.type == 'change') { - self._changed = true; + // Trigger command event on change + if (event.type == 'keypress' || event.type == 'change') { + self._timer = self.timeout && setTimeout(function () { + var attr = self.getAttribute('oncommand'); + attr = attr.replace('this', 'thisObj'); + var func = new Function('thisObj', 'event', attr); + func(self, event); + }, self.timeout); } - // Get the command event - self._timer = self.timeout && setTimeout(function () { - var attr = self.getAttribute('oncommand'); - attr = attr.replace('this', 'thisObj'); - var func = new Function('thisObj', 'event', attr); - func(self, event); - }, self.timeout); - return true; }; break;