use square brackets, select to make cloze

This commit is contained in:
Damien Elmes 2009-02-09 17:15:58 +09:00
parent c10ea4f255
commit eb7620eb76

View file

@ -674,6 +674,15 @@ class FactEditor(object):
src = self.focusedEdit() src = self.focusedEdit()
if not src: if not src:
return return
# add brackets because selected?
cursor = src.textCursor()
if cursor.hasSelection():
s = cursor.selectionStart()
e = cursor.selectionEnd()
cursor.setPosition(e)
cursor.insertText("]")
cursor.setPosition(s)
cursor.insertText("[")
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():
@ -703,7 +712,7 @@ class FactEditor(object):
parent=self.parent) parent=self.parent)
return return
# check if there's anything to change # check if there's anything to change
if not re.search("\(.+?\)", unicode(src.toPlainText())): if not re.search("\[.+?\]", unicode(src.toPlainText())):
QDesktopServices.openUrl(QUrl(ankiqt.appWiki + QDesktopServices.openUrl(QUrl(ankiqt.appWiki +
"ClozeDeletion")) "ClozeDeletion"))
return return
@ -713,10 +722,10 @@ class FactEditor(object):
exp = "" exp = ""
if match.group(2): if match.group(2):
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("\[.+?(:(.+?))?\]", repl, s)
old = re.sub("\((.+?)(:.+?)?\)", '<font color="%s"><b>\\1</b></font>' old = re.sub("\[(.+?)(:.+?)?\]", '<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)