diff --git a/CHANGELOG.md b/CHANGELOG.md index f987594b..06f51d75 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -229,11 +229,28 @@ final release. ---- +## Version 1.6.6 [2022-10-25] + +### Release Notes + +This is a bugfix release that fixes a minor issues with following tags in the editor. It is now +possible to also follow tags that contain spaces. + +### Detailed Changelog + +**Bugfixes** + +* Fix a bug where only the word under the cursor would be looked up when the user tried to follow a + tag in the editor. The lookup function now uses the same parser for the `@`-line as the syntax + highlighter does, so they should behave consistently. Issue #1195. PR #1209. + +---- + ## Version 1.6.5 [2022-10-13] ### Release Notes -This is a bugfix release that fixes a a few minor issues. The idle time for new projects would be +This is a bugfix release that fixes a few minor issues. The idle time for new projects would be artificially inflated as the clock was not reset when the project was first created. This only affects the first entry in the writing statistics. A scaling issue for the Preferences dialog has also been fixed. It only affected screens with UI scaling enabled. Lastly, typing `Shift+Enter` in diff --git a/novelwriter/gui/doceditor.py b/novelwriter/gui/doceditor.py index 8a1b60bb..564e23c3 100644 --- a/novelwriter/gui/doceditor.py +++ b/novelwriter/gui/doceditor.py @@ -1874,10 +1874,10 @@ class GuiDocEditor(QTextEdit): def _followTag(self, theCursor=None, loadTag=True): """Activated by Ctrl+Enter. Checks that we're in a block - starting with '@'. We then find the word under the cursor and - check that it is after the ':'. If all this is fine, we have a - tag and can tell the document viewer to try and find and load - the file where the tag is defined. + starting with '@'. We then find the tag under the cursor and + check that it is not the tag itself. If all this is fine, we + have a tag and can tell the document viewer to try and find and + load the file where the tag is defined. """ if theCursor is None: theCursor = self.textCursor() @@ -1890,18 +1890,29 @@ class GuiDocEditor(QTextEdit): if theText.startswith("@"): - theCursor.select(QTextCursor.WordUnderCursor) - theWord = theCursor.selectedText() - cPos = theText.find(":") - wPos = theCursor.selectionStart() - theBlock.position() - if wPos <= cPos: + isGood, tBits, tPos = self.theProject.index.scanThis(theText) + if not isGood: + return False + + 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 if loadTag: - logger.debug("Attempting to follow tag '%s'", theWord) - self.loadDocumentTagRequest.emit(theWord, nwDocMode.VIEW) + logger.debug("Attempting to follow tag '%s'", theTag) + self.loadDocumentTagRequest.emit(theTag, nwDocMode.VIEW) else: - logger.debug("Potential tag '%s'", theWord) + logger.debug("Potential tag '%s'", theTag) return True diff --git a/sample/nwProject.nwx b/sample/nwProject.nwx index e32d66f8..535b6d18 100644 --- a/sample/nwProject.nwx +++ b/sample/nwProject.nwx @@ -1,13 +1,13 @@ - + Sample Project Sample Project Jane Smith Jay Doh - 1385 + 1386 236 - 69348 + 69352 False