Added ctrl + mouse click to follow tags as well.

This commit is contained in:
Veronica K. B. Olsen
2019-10-30 21:49:48 +01:00
parent e78830b3a2
commit 9342f90a41
+17 -5
View File
@@ -16,7 +16,7 @@ import nw
from time import time
from PyQt5.QtCore import Qt, QTimer, QSizeF
from PyQt5.QtWidgets import QTextEdit, QAction, QMenu, QShortcut
from PyQt5.QtWidgets import qApp, QTextEdit, QAction, QMenu, QShortcut
from PyQt5.QtGui import QTextCursor, QTextOption, QIcon, QKeySequence, QFont, QColor, QPalette, QTextDocument
from nw.project.document import NWDoc
@@ -352,19 +352,31 @@ class GuiDocEditor(QTextEdit):
return
def mouseReleaseEvent(self, mEvent):
"""If the mouse button is released and the control key is pressed, check if we're clicking
on a tag, and trigger the follow tag function.
"""
if qApp.keyboardModifiers() == Qt.ControlModifier:
theCursor = self.cursorForPosition(mEvent.pos())
self._followTag(theCursor)
QTextEdit.mouseReleaseEvent(self, mEvent)
return
##
# Internal Functions
##
def _followTag(self):
def _followTag(self, theCursor=None):
"""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.
"""
theCursor = self.textCursor()
theBlock = theCursor.block()
theText = theBlock.text()
if theCursor is None:
theCursor = self.textCursor()
theBlock = theCursor.block()
theText = theBlock.text()
if len(theText) == 0:
return False