From dc0f9abdbc19cb4c9293c171b12ed466ca0dbf2d Mon Sep 17 00:00:00 2001 From: Veronica Berglyd Olsen <1619840+vkbo@users.noreply.github.com> Date: Tue, 25 Oct 2022 18:12:29 +0200 Subject: [PATCH 1/2] Fix lookup of tags with spaces (#1195) --- novelwriter/gui/doceditor.py | 35 +++++++++++++++++++++++------------ 1 file changed, 23 insertions(+), 12 deletions(-) diff --git a/novelwriter/gui/doceditor.py b/novelwriter/gui/doceditor.py index 83d971d5..e1ed9816 100644 --- a/novelwriter/gui/doceditor.py +++ b/novelwriter/gui/doceditor.py @@ -1871,10 +1871,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() @@ -1887,18 +1887,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.theParent.theIndex.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.verbose("Attempting to follow tag '%s'", theWord) - self.theParent.docViewer.loadFromTag(theWord) + logger.verbose("Attempting to follow tag '%s'", theTag) + self.theParent.docViewer.loadFromTag(theTag) else: - logger.verbose("Potential tag '%s'", theWord) + logger.verbose("Potential tag '%s'", theTag) return True From 4862ac385761bf84c6532751284d00bd4810977a Mon Sep 17 00:00:00 2001 From: Veronica Berglyd Olsen <1619840+vkbo@users.noreply.github.com> Date: Tue, 25 Oct 2022 18:26:37 +0200 Subject: [PATCH 2/2] Bump the version number and update the changelog --- CHANGELOG.md | 19 ++++++++++++++++++- novelwriter/__init__.py | 6 +++--- novelwriter/assets/text/release_notes.htm | 7 ++++++- sample/nwProject.nwx | 8 ++++---- 4 files changed, 31 insertions(+), 9 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 300f82fd..e27e65af 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,10 +1,27 @@ # novelWriter Changelog +## 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/__init__.py b/novelwriter/__init__.py index 2b40a55f..b76e94ec 100644 --- a/novelwriter/__init__.py +++ b/novelwriter/__init__.py @@ -60,9 +60,9 @@ __license__ = "GPLv3" __author__ = "Veronica Berglyd Olsen" __maintainer__ = "Veronica Berglyd Olsen" __email__ = "code@vkbo.net" -__version__ = "1.6.5" -__hexversion__ = "0x010605f0" -__date__ = "2022-10-13" +__version__ = "1.6.6" +__hexversion__ = "0x010606f0" +__date__ = "2022-10-25" __status__ = "Stable" __domain__ = "novelwriter.io" __url__ = "https://novelwriter.io" diff --git a/novelwriter/assets/text/release_notes.htm b/novelwriter/assets/text/release_notes.htm index 34c423a8..1db03b01 100644 --- a/novelwriter/assets/text/release_notes.htm +++ b/novelwriter/assets/text/release_notes.htm @@ -72,7 +72,7 @@ text cursor sometimes disappears when reaching the right-hand edge of the text e
This is a bugfix release that fixes a a few minor issues. The idle time for new projects would +
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 @@ -80,5 +80,10 @@ the text editor now creates a regular line break instead of a special line separ separator serves no purpose in plain text, and was producing inconsistencies in how text is processed and displayed.
+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.
+