mirror of
https://github.com/ankitects/anki.git
synced 2025-09-24 08:46:37 -04: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']:
|
||||
openHelp("cloze")
|
||||
return
|
||||
f = self.note.fields[self.currentField]
|
||||
# find the highest existing cloze
|
||||
m = re.findall("\{\{c(\d+)::", f)
|
||||
if m:
|
||||
next = sorted([int(x) for x in m])[-1] + 1
|
||||
if self.mw.app.keyboardModifiers() & Qt.AltModifier:
|
||||
next -= 1
|
||||
else:
|
||||
next = 1
|
||||
self._eval("wrap('{{c%d::', '}}');" % next)
|
||||
highest = 0
|
||||
for name, val in self.note.items():
|
||||
m = re.findall("\{\{c(\d+)::", val)
|
||||
if m:
|
||||
highest = max(highest, sorted([int(x) for x in m])[-1])
|
||||
# reuse last?
|
||||
if not self.mw.app.keyboardModifiers() & Qt.AltModifier:
|
||||
highest += 1
|
||||
# must start at 1
|
||||
highest = max(1, highest)
|
||||
self._eval("wrap('{{c%d::', '}}');" % highest)
|
||||
|
||||
def _eval(self, str):
|
||||
# some versions of webkit crash if we try a dom-modifying operation
|
||||
|
|
Loading…
Reference in a new issue