From 3fa597ed1a2ce6594d7f8cb365df867a2d68a369 Mon Sep 17 00:00:00 2001 From: Damien Elmes Date: Tue, 12 Jul 2016 13:30:10 +1000 Subject: [PATCH] wait until saveNow() is done fixes content missing if typed right before save, and add window complaining that fields aren't empty when they appear so --- aqt/editor.py | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) diff --git a/aqt/editor.py b/aqt/editor.py index a0a05b00c..f204f1843 100644 --- a/aqt/editor.py +++ b/aqt/editor.py @@ -79,6 +79,12 @@ function setFGButton(col) { $("#forecolor")[0].style.backgroundColor = col; }; +function saveNow() { + if (currentField) { + currentField.blur(); + } +}; + function onKey() { // esc clears focus, allowing dialog to close if (window.event.which == 27) { @@ -581,9 +587,14 @@ class Editor(object): return self.saveTags() # move focus out of fields and save tags - self.parentWindow.setFocus() - # and process events so any focus-lost hooks fire - self.mw.app.processEvents() + self._saveNowWaiting = True + self.web.evalWithCallback("saveNow()", self._saveNowDone) + while self._saveNowWaiting: + # and process events so any focus-lost hooks fire + self.mw.app.processEvents() + + def _saveNowDone(self, res): + self._saveNowWaiting = False def checkValid(self): cols = []