From bddba8079e8e64e6f48fc6154fd082458888dc48 Mon Sep 17 00:00:00 2001 From: Damien Elmes Date: Tue, 24 Apr 2012 02:10:11 +0900 Subject: [PATCH] check for highest cloze across all fields --- aqt/editor.py | 20 +++++++++++--------- 1 file changed, 11 insertions(+), 9 deletions(-) diff --git a/aqt/editor.py b/aqt/editor.py index b512cfa45..f18737942 100644 --- a/aqt/editor.py +++ b/aqt/editor.py @@ -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