if there's a selection, ignore []s in cloze

This commit is contained in:
Damien Elmes 2009-03-06 04:57:11 +09:00
parent d2528e8605
commit 7c02fe3c86

View file

@ -679,15 +679,19 @@ class FactEditor(object):
src = self.focusedEdit() src = self.focusedEdit()
if not src: if not src:
return return
re1 = "\[.+?(:(.+?))?\]"
re2 = "\[(.+?)(:.+?)?\]"
# add brackets because selected? # add brackets because selected?
cursor = src.textCursor() cursor = src.textCursor()
if cursor.hasSelection(): if cursor.hasSelection():
s = cursor.selectionStart() s = cursor.selectionStart()
e = cursor.selectionEnd() e = cursor.selectionEnd()
cursor.setPosition(e) cursor.setPosition(e)
cursor.insertText("]") cursor.insertText("]]")
cursor.setPosition(s) cursor.setPosition(s)
cursor.insertText("[") cursor.insertText("[[")
re1 = "\[" + re1 + "\]"
re2 = "\[" + re2 + "\]"
dst = None dst = None
for (name, (field, w)) in self.fields.items(): for (name, (field, w)) in self.fields.items():
if w.hasFocus(): if w.hasFocus():
@ -729,8 +733,8 @@ class FactEditor(object):
exp = match.group(2) exp = match.group(2)
return '<font color="%s"><b>[...%s]</b></font>' % ( return '<font color="%s"><b>[...%s]</b></font>' % (
clozeColour, exp) clozeColour, exp)
new = re.sub("\[.+?(:(.+?))?\]", repl, s) new = re.sub(re1, repl, s)
old = re.sub("\[(.+?)(:.+?)?\]", '<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()) oldSrc = unicode(src.toHtml())
src.setHtml(new) src.setHtml(new)