mirror of
https://github.com/ankitects/anki.git
synced 2025-09-21 23:42:23 -04:00
sync field contents before applying cloze deletion
based on a patch by dlon: https://github.com/dae/anki/pull/236
This commit is contained in:
parent
4cee52a994
commit
46a540e22f
2 changed files with 14 additions and 4 deletions
|
@ -332,14 +332,14 @@ class Editor:
|
|||
return [(f['font'], f['size'], f['rtl'])
|
||||
for f in self.note.model()['flds']]
|
||||
|
||||
def saveNow(self, callback):
|
||||
def saveNow(self, callback, keepFocus=False):
|
||||
"Save unsaved edits then call callback()."
|
||||
if not self.note:
|
||||
# calling code may not expect the callback to fire immediately
|
||||
self.mw.progress.timer(10, callback, False)
|
||||
return
|
||||
self.saveTags()
|
||||
self.web.evalWithCallback("saveNow()", lambda res: callback())
|
||||
self.web.evalWithCallback("saveNow(%d)" % keepFocus, lambda res: callback())
|
||||
|
||||
def checkValid(self):
|
||||
cols = []
|
||||
|
@ -472,6 +472,9 @@ class Editor:
|
|||
self.web.eval("setFormat('removeFormat');")
|
||||
|
||||
def onCloze(self):
|
||||
self.saveNow(self._onCloze, keepFocus=True)
|
||||
|
||||
def _onCloze(self):
|
||||
# check that the model is set up for cloze deletion
|
||||
if not re.search('{{(.*:)*cloze:',self.note.model()['tmpls'][0]['qfmt']):
|
||||
if self.addMode:
|
||||
|
|
|
@ -14,9 +14,16 @@ function setFGButton(col) {
|
|||
$("#forecolor")[0].style.backgroundColor = col;
|
||||
}
|
||||
|
||||
function saveNow() {
|
||||
function saveNow(keepFocus) {
|
||||
if (!currentField) {
|
||||
return;
|
||||
}
|
||||
|
||||
clearChangeTimer();
|
||||
if (currentField) {
|
||||
|
||||
if (keepFocus) {
|
||||
saveField("key");
|
||||
} else {
|
||||
currentField.blur();
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue