diff --git a/ankiqt/ui/facteditor.py b/ankiqt/ui/facteditor.py index 7e99483e0..a26b2a19d 100644 --- a/ankiqt/ui/facteditor.py +++ b/ankiqt/ui/facteditor.py @@ -679,15 +679,19 @@ class FactEditor(object): src = self.focusedEdit() if not src: return + re1 = "\[.+?(:(.+?))?\]" + re2 = "\[(.+?)(:.+?)?\]" # add brackets because selected? cursor = src.textCursor() if cursor.hasSelection(): s = cursor.selectionStart() e = cursor.selectionEnd() cursor.setPosition(e) - cursor.insertText("]") + cursor.insertText("]]") cursor.setPosition(s) - cursor.insertText("[") + cursor.insertText("[[") + re1 = "\[" + re1 + "\]" + re2 = "\[" + re2 + "\]" dst = None for (name, (field, w)) in self.fields.items(): if w.hasFocus(): @@ -729,8 +733,8 @@ class FactEditor(object): exp = match.group(2) return '[...%s]' % ( clozeColour, exp) - new = re.sub("\[.+?(:(.+?))?\]", repl, s) - old = re.sub("\[(.+?)(:.+?)?\]", '\\1' + new = re.sub(re1, repl, s) + old = re.sub(re2, '\\1' % clozeColour, s) oldSrc = unicode(src.toHtml()) src.setHtml(new)