mirror of
https://github.com/ankitects/anki.git
synced 2025-09-22 16:02: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'])
|
return [(f['font'], f['size'], f['rtl'])
|
||||||
for f in self.note.model()['flds']]
|
for f in self.note.model()['flds']]
|
||||||
|
|
||||||
def saveNow(self, callback):
|
def saveNow(self, callback, keepFocus=False):
|
||||||
"Save unsaved edits then call callback()."
|
"Save unsaved edits then call callback()."
|
||||||
if not self.note:
|
if not self.note:
|
||||||
# calling code may not expect the callback to fire immediately
|
# calling code may not expect the callback to fire immediately
|
||||||
self.mw.progress.timer(10, callback, False)
|
self.mw.progress.timer(10, callback, False)
|
||||||
return
|
return
|
||||||
self.saveTags()
|
self.saveTags()
|
||||||
self.web.evalWithCallback("saveNow()", lambda res: callback())
|
self.web.evalWithCallback("saveNow(%d)" % keepFocus, lambda res: callback())
|
||||||
|
|
||||||
def checkValid(self):
|
def checkValid(self):
|
||||||
cols = []
|
cols = []
|
||||||
|
@ -472,6 +472,9 @@ class Editor:
|
||||||
self.web.eval("setFormat('removeFormat');")
|
self.web.eval("setFormat('removeFormat');")
|
||||||
|
|
||||||
def onCloze(self):
|
def onCloze(self):
|
||||||
|
self.saveNow(self._onCloze, keepFocus=True)
|
||||||
|
|
||||||
|
def _onCloze(self):
|
||||||
# check that the model is set up for cloze deletion
|
# check that the model is set up for cloze deletion
|
||||||
if not re.search('{{(.*:)*cloze:',self.note.model()['tmpls'][0]['qfmt']):
|
if not re.search('{{(.*:)*cloze:',self.note.model()['tmpls'][0]['qfmt']):
|
||||||
if self.addMode:
|
if self.addMode:
|
||||||
|
|
|
@ -14,9 +14,16 @@ function setFGButton(col) {
|
||||||
$("#forecolor")[0].style.backgroundColor = col;
|
$("#forecolor")[0].style.backgroundColor = col;
|
||||||
}
|
}
|
||||||
|
|
||||||
function saveNow() {
|
function saveNow(keepFocus) {
|
||||||
|
if (!currentField) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
clearChangeTimer();
|
clearChangeTimer();
|
||||||
if (currentField) {
|
|
||||||
|
if (keepFocus) {
|
||||||
|
saveField("key");
|
||||||
|
} else {
|
||||||
currentField.blur();
|
currentField.blur();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue