From 4607d42c5f17ec800c1c94d5c9da4386f66d2fe9 Mon Sep 17 00:00:00 2001 From: Damien Elmes Date: Fri, 6 Mar 2009 06:06:50 +0900 Subject: [PATCH] fix cloze undo --- ankiqt/ui/facteditor.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/ankiqt/ui/facteditor.py b/ankiqt/ui/facteditor.py index 7a109eb65..14e598baf 100644 --- a/ankiqt/ui/facteditor.py +++ b/ankiqt/ui/facteditor.py @@ -680,7 +680,9 @@ class FactEditor(object): re2 = "\[(.+?)(:.+?)?\]" # add brackets because selected? cursor = src.textCursor() + oldSrc = None if cursor.hasSelection(): + oldSrc = src.toHtml() s = cursor.selectionStart() e = cursor.selectionEnd() cursor.setPosition(e) @@ -703,7 +705,8 @@ class FactEditor(object): if dst == w: return # check if there's alredy something there - oldSrc = src.toHtml() + if not oldSrc: + oldSrc = src.toHtml() oldDst = dst.toHtml() if unicode(dst.toPlainText()): if (self.lastCloze and @@ -734,7 +737,6 @@ class FactEditor(object): new = re.sub(re1, repl, s) old = re.sub(re2, '\\1' % clozeColour, s) - oldSrc = unicode(src.toHtml()) src.setHtml(new) dst.setHtml(old) self.lastCloze = (oldSrc, unicode(src.toHtml()),