From 19f89388529737d019fed4358beed8d1e633093d Mon Sep 17 00:00:00 2001 From: Olivier Keshavjee Date: Fri, 15 Dec 2017 20:12:51 +0100 Subject: [PATCH] Corrects bug in links tooltips --- manuskript/ui/views/MDEditView.py | 21 ++++++++++++--------- 1 file changed, 12 insertions(+), 9 deletions(-) diff --git a/manuskript/ui/views/MDEditView.py b/manuskript/ui/views/MDEditView.py index 48f1c0e1..cba07a26 100644 --- a/manuskript/ui/views/MDEditView.py +++ b/manuskript/ui/views/MDEditView.py @@ -19,6 +19,9 @@ class MDEditView(textEditView): blockquoteRegex = QRegExp("^ {0,3}(>\\s*)+") listRegex = QRegExp("^(\\s*)([+*-]|([0-9a-z])+([.\)]))(\\s+)") + inlineLinkRegex = QRegExp("\\[([^\n]+)\\]\\(([^\n]+)\\)") + imageRegex = QRegExp("!\\[([^\n]*)\\]\\(([^\n]+)\\)") + automaticLinkRegex = QRegExp("(<([a-zA-Z]+\\:[^\n]+)>)|(<([^\n]+@[^\n]+)>)") def __init__(self, parent=None, index=None, html=None, spellcheck=True, highlighting=False, dict="", autoResize=False): @@ -465,9 +468,9 @@ class MDEditView(textEditView): refs = [] text = self.toPlainText() for rx in [ - MT.imageRegex, - MT.automaticLinkRegex, - MT.inlineLinkRegex, + self.imageRegex, + self.automaticLinkRegex, + self.inlineLinkRegex, ]: pos = 0 while rx.indexIn(text, pos) != -1: @@ -516,17 +519,17 @@ class MDEditView(textEditView): if not qApp.overrideCursor(): qApp.setOverrideCursor(Qt.PointingHandCursor) - if ct.regex == MT.automaticLinkRegex: + if ct.regex == self.automaticLinkRegex: tooltip = ct.texts[2] or ct.texts[4] - elif ct.regex == MT.imageRegex: + elif ct.regex == self.imageRegex: tt = ("

" + ct.texts[1] + "

" +"

") tooltip = None pos = event.pos() + QPoint(0, ct.rect.height()) imageTooltiper.fromUrl(ct.texts[2], pos, self) - elif ct.regex == MT.inlineLinkRegex: + elif ct.regex == self.inlineLinkRegex: tooltip = ct.texts[1] or ct.texts[2] if tooltip: @@ -539,11 +542,11 @@ class MDEditView(textEditView): if onRect and event.modifiers() & Qt.ControlModifier: ct = onRect[0] - if ct.regex == MT.automaticLinkRegex: + if ct.regex == self.automaticLinkRegex: url = ct.texts[2] or ct.texts[4] - elif ct.regex == MT.imageRegex: + elif ct.regex == self.imageRegex: url = ct.texts[2] - elif ct.regex == MT.inlineLinkRegex: + elif ct.regex == self.inlineLinkRegex: url = ct.texts[2] F.openURL(url)