fix cloze undo

This commit is contained in:
Damien Elmes 2009-03-06 06:06:50 +09:00
parent f6a1a8fc63
commit 4607d42c5f

View file

@ -680,7 +680,9 @@ class FactEditor(object):
re2 = "\[(.+?)(:.+?)?\]" re2 = "\[(.+?)(:.+?)?\]"
# add brackets because selected? # add brackets because selected?
cursor = src.textCursor() cursor = src.textCursor()
oldSrc = None
if cursor.hasSelection(): if cursor.hasSelection():
oldSrc = src.toHtml()
s = cursor.selectionStart() s = cursor.selectionStart()
e = cursor.selectionEnd() e = cursor.selectionEnd()
cursor.setPosition(e) cursor.setPosition(e)
@ -703,7 +705,8 @@ class FactEditor(object):
if dst == w: if dst == w:
return return
# check if there's alredy something there # check if there's alredy something there
oldSrc = src.toHtml() if not oldSrc:
oldSrc = src.toHtml()
oldDst = dst.toHtml() oldDst = dst.toHtml()
if unicode(dst.toPlainText()): if unicode(dst.toPlainText()):
if (self.lastCloze and if (self.lastCloze and
@ -734,7 +737,6 @@ class FactEditor(object):
new = re.sub(re1, repl, s) new = re.sub(re1, repl, s)
old = re.sub(re2, '<font color="%s"><b>\\1</b></font>' old = re.sub(re2, '<font color="%s"><b>\\1</b></font>'
% clozeColour, s) % clozeColour, s)
oldSrc = unicode(src.toHtml())
src.setHtml(new) src.setHtml(new)
dst.setHtml(old) dst.setHtml(old)
self.lastCloze = (oldSrc, unicode(src.toHtml()), self.lastCloze = (oldSrc, unicode(src.toHtml()),