Fix lookup of tags with spaces (#1195)
This commit is contained in:
@@ -1871,10 +1871,10 @@ class GuiDocEditor(QTextEdit):
|
|||||||
|
|
||||||
def _followTag(self, theCursor=None, loadTag=True):
|
def _followTag(self, theCursor=None, loadTag=True):
|
||||||
"""Activated by Ctrl+Enter. Checks that we're in a block
|
"""Activated by Ctrl+Enter. Checks that we're in a block
|
||||||
starting with '@'. We then find the word under the cursor and
|
starting with '@'. We then find the tag under the cursor and
|
||||||
check that it is after the ':'. If all this is fine, we have a
|
check that it is not the tag itself. If all this is fine, we
|
||||||
tag and can tell the document viewer to try and find and load
|
have a tag and can tell the document viewer to try and find and
|
||||||
the file where the tag is defined.
|
load the file where the tag is defined.
|
||||||
"""
|
"""
|
||||||
if theCursor is None:
|
if theCursor is None:
|
||||||
theCursor = self.textCursor()
|
theCursor = self.textCursor()
|
||||||
@@ -1887,18 +1887,29 @@ class GuiDocEditor(QTextEdit):
|
|||||||
|
|
||||||
if theText.startswith("@"):
|
if theText.startswith("@"):
|
||||||
|
|
||||||
theCursor.select(QTextCursor.WordUnderCursor)
|
isGood, tBits, tPos = self.theParent.theIndex.scanThis(theText)
|
||||||
theWord = theCursor.selectedText()
|
if not isGood:
|
||||||
cPos = theText.find(":")
|
return False
|
||||||
wPos = theCursor.selectionStart() - theBlock.position()
|
|
||||||
if wPos <= cPos:
|
theTag = ""
|
||||||
|
cPos = theCursor.selectionStart() - theBlock.position()
|
||||||
|
for sTag, sPos in zip(reversed(tBits), reversed(tPos)):
|
||||||
|
if cPos >= sPos:
|
||||||
|
# The cursor is between the start of two tags
|
||||||
|
if cPos <= sPos + len(sTag):
|
||||||
|
# The cursor is inside or at the edge of the tag
|
||||||
|
theTag = sTag
|
||||||
|
break
|
||||||
|
|
||||||
|
if not theTag or theTag.startswith("@"):
|
||||||
|
# The keyword cannot be looked up, so we ignore that
|
||||||
return False
|
return False
|
||||||
|
|
||||||
if loadTag:
|
if loadTag:
|
||||||
logger.verbose("Attempting to follow tag '%s'", theWord)
|
logger.verbose("Attempting to follow tag '%s'", theTag)
|
||||||
self.theParent.docViewer.loadFromTag(theWord)
|
self.theParent.docViewer.loadFromTag(theTag)
|
||||||
else:
|
else:
|
||||||
logger.verbose("Potential tag '%s'", theWord)
|
logger.verbose("Potential tag '%s'", theTag)
|
||||||
|
|
||||||
return True
|
return True
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user