From 38178e5281b4bd4a33177230158a1ddd74468c09 Mon Sep 17 00:00:00 2001 From: Damien Elmes Date: Mon, 30 Apr 2018 14:51:49 +1000 Subject: [PATCH] catch attempts to save field contents to wrong note --- aqt/editor.py | 11 ++++++++--- web/editor.js | 7 ++++++- 2 files changed, 14 insertions(+), 4 deletions(-) diff --git a/aqt/editor.py b/aqt/editor.py index 7084fc450..ebd3d18b5 100644 --- a/aqt/editor.py +++ b/aqt/editor.py @@ -242,8 +242,12 @@ class Editor: return # focus lost or key/button pressed? if cmd.startswith("blur") or cmd.startswith("key"): - (type, ord, txt) = cmd.split(":", 2) + (type, ord, nid, txt) = cmd.split(":", 3) ord = int(ord) + nid = int(nid) + if nid != self.note.id: + print("ignored late blur") + return txt = urllib.parse.unquote(txt) txt = unicodedata.normalize("NFC", txt) txt = self.mungeHTML(txt) @@ -318,9 +322,10 @@ class Editor: self.web.setFocus() runHook("loadNote", self) - self.web.evalWithCallback("setFields(%s); setFonts(%s); focusField(%s)" % ( + self.web.evalWithCallback("setFields(%s); setFonts(%s); focusField(%s); setNoteId(%s)" % ( json.dumps(data), - json.dumps(self.fonts()), json.dumps(focusTo)), + json.dumps(self.fonts()), json.dumps(focusTo), + json.dumps(self.note.id)), oncallback) def fonts(self): diff --git a/web/editor.js b/web/editor.js index b74035de6..5295837a8 100644 --- a/web/editor.js +++ b/web/editor.js @@ -1,6 +1,7 @@ var currentField = null; var changeTimer = null; var dropTarget = null; +var currentNoteId = null; String.prototype.format = function () { var args = arguments; @@ -203,7 +204,7 @@ function saveField(type) { return; } // type is either 'blur' or 'key' - pycmd(type + ":" + currentFieldOrdinal() + ":" + currentField.innerHTML); + pycmd(type + ":" + currentFieldOrdinal() + ":" + currentNoteId + ":" + currentField.innerHTML); clearChangeTimer(); } @@ -295,6 +296,10 @@ function setFonts(fonts) { } } +function setNoteId(id) { + currentNoteId = id; +} + function showDupes() { $("#dupes").show(); }