Skip to content

Commit e93e125

Browse files
authored
Allow lookup of tags with spaces (#1209)
2 parents 0e94b1c + dc0f9ab commit e93e125

File tree

1 file changed

+23
-12
lines changed

1 file changed

+23
-12
lines changed

novelwriter/gui/doceditor.py

Lines changed: 23 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1871,10 +1871,10 @@ def _removeInParLineBreaks(self):
18711871

18721872
def _followTag(self, theCursor=None, loadTag=True):
18731873
"""Activated by Ctrl+Enter. Checks that we're in a block
1874-
starting with '@'. We then find the word under the cursor and
1875-
check that it is after the ':'. If all this is fine, we have a
1876-
tag and can tell the document viewer to try and find and load
1877-
the file where the tag is defined.
1874+
starting with '@'. We then find the tag under the cursor and
1875+
check that it is not the tag itself. If all this is fine, we
1876+
have a tag and can tell the document viewer to try and find and
1877+
load the file where the tag is defined.
18781878
"""
18791879
if theCursor is None:
18801880
theCursor = self.textCursor()
@@ -1887,18 +1887,29 @@ def _followTag(self, theCursor=None, loadTag=True):
18871887

18881888
if theText.startswith("@"):
18891889

1890-
theCursor.select(QTextCursor.WordUnderCursor)
1891-
theWord = theCursor.selectedText()
1892-
cPos = theText.find(":")
1893-
wPos = theCursor.selectionStart() - theBlock.position()
1894-
if wPos <= cPos:
1890+
isGood, tBits, tPos = self.theParent.theIndex.scanThis(theText)
1891+
if not isGood:
1892+
return False
1893+
1894+
theTag = ""
1895+
cPos = theCursor.selectionStart() - theBlock.position()
1896+
for sTag, sPos in zip(reversed(tBits), reversed(tPos)):
1897+
if cPos >= sPos:
1898+
# The cursor is between the start of two tags
1899+
if cPos <= sPos + len(sTag):
1900+
# The cursor is inside or at the edge of the tag
1901+
theTag = sTag
1902+
break
1903+
1904+
if not theTag or theTag.startswith("@"):
1905+
# The keyword cannot be looked up, so we ignore that
18951906
return False
18961907

18971908
if loadTag:
1898-
logger.verbose("Attempting to follow tag '%s'", theWord)
1899-
self.theParent.docViewer.loadFromTag(theWord)
1909+
logger.verbose("Attempting to follow tag '%s'", theTag)
1910+
self.theParent.docViewer.loadFromTag(theTag)
19001911
else:
1901-
logger.verbose("Potential tag '%s'", theWord)
1912+
logger.verbose("Potential tag '%s'", theTag)
19021913

19031914
return True
19041915

0 commit comments

Comments
 (0)