diff --git a/novelwriter/gui/docviewer.py b/novelwriter/gui/docviewer.py index c111f6a1..2449688d 100644 --- a/novelwriter/gui/docviewer.py +++ b/novelwriter/gui/docviewer.py @@ -1201,17 +1201,18 @@ class GuiDocViewDetails(QScrollArea): return ## - # Internal Functions + # Private Slots ## + @pyqtSlot(str) def _linkClicked(self, theLink): """Capture the link-click and forward it to the document viewer class for handling. """ logger.debug("Clicked link: '%s'", theLink) - if len(theLink) == 21: + if len(theLink) >= 13: tHandle = theLink[:13] - tAnchor = theLink[13:] + tAnchor = theLink[13:] or None self.mainGui.viewDocument(tHandle, tAnchor) return diff --git a/tests/test_gui/test_gui_docviewer.py b/tests/test_gui/test_gui_docviewer.py index 02f6002f..14cf66d0 100644 --- a/tests/test_gui/test_gui_docviewer.py +++ b/tests/test_gui/test_gui_docviewer.py @@ -171,6 +171,19 @@ def testGuiViewer_Main(qtbot, monkeypatch, nwGUI, nwLipsum): assert nwGUI.docViewer.loadText("846352075de7d") is False assert nwGUI.docViewer.toPlainText() == "An error occurred while generating the preview." + # Check reference panel (issue #1378) + assert nwGUI.viewDocument("4c4f28287af27") is True + assert nwGUI.docViewer.toPlainText().startswith("Nobody Owens") + + nwGUI.viewMeta._linkClicked("fb609cd8319dc") + assert nwGUI.docViewer.toPlainText().startswith("Chapter One") + + nwGUI.viewMeta._linkClicked("88243afbe5ed8#T0001") + assert nwGUI.docViewer.toPlainText().startswith("Scene One") + + nwGUI.viewMeta._linkClicked("88243afbe5ed8#ABCD") + assert nwGUI.docViewer.toPlainText().startswith("Scene One") + # qtbot.stop() # END Test testGuiViewer_Main