mirror of
https://github.com/ankitects/anki.git
synced 2025-11-08 13:47:13 -05:00
check for highest cloze across all fields
This commit is contained in:
parent
9c19fa8f69
commit
bddba8079e
1 changed files with 11 additions and 9 deletions
|
|
@ -693,16 +693,18 @@ class Editor(object):
|
||||||
if '{{cloze:' not in self.note.model()['tmpls'][0]['qfmt']:
|
if '{{cloze:' not in self.note.model()['tmpls'][0]['qfmt']:
|
||||||
openHelp("cloze")
|
openHelp("cloze")
|
||||||
return
|
return
|
||||||
f = self.note.fields[self.currentField]
|
|
||||||
# find the highest existing cloze
|
# find the highest existing cloze
|
||||||
m = re.findall("\{\{c(\d+)::", f)
|
highest = 0
|
||||||
if m:
|
for name, val in self.note.items():
|
||||||
next = sorted([int(x) for x in m])[-1] + 1
|
m = re.findall("\{\{c(\d+)::", val)
|
||||||
if self.mw.app.keyboardModifiers() & Qt.AltModifier:
|
if m:
|
||||||
next -= 1
|
highest = max(highest, sorted([int(x) for x in m])[-1])
|
||||||
else:
|
# reuse last?
|
||||||
next = 1
|
if not self.mw.app.keyboardModifiers() & Qt.AltModifier:
|
||||||
self._eval("wrap('{{c%d::', '}}');" % next)
|
highest += 1
|
||||||
|
# must start at 1
|
||||||
|
highest = max(1, highest)
|
||||||
|
self._eval("wrap('{{c%d::', '}}');" % highest)
|
||||||
|
|
||||||
def _eval(self, str):
|
def _eval(self, str):
|
||||||
# some versions of webkit crash if we try a dom-modifying operation
|
# some versions of webkit crash if we try a dom-modifying operation
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue