@@ -148,6 +148,10 @@ def __init__(self, parent):
148148 # it on.
149149 self .setVerticalScrollBarPolicy (Qt .ScrollBarPolicy .ScrollBarAlwaysOn )
150150
151+ # Variable to store text cursor pos, so as not to move cursor when
152+ # clicking a hyperlink.
153+ self .textCursorPos = None
154+
151155 def setCodeHighlighter (self , highlight ):
152156 """Set the code highlighter for the console
153157
@@ -225,6 +229,8 @@ def mousePressEvent(self, event):
225229 check release position. If it's the same (ie user clicked vs click-drag to
226230 select text), we check if user clicked an error hyperlink.
227231 """
232+ self .textCursorPos = self .textCursor ().position ()
233+
228234 self .clickPos = event .pos ()
229235 self .anchor = self .anchorAt (event .pos ())
230236 if self .anchor :
@@ -237,13 +243,24 @@ def mouseReleaseEvent(self, event):
237243 """
238244 samePos = event .pos () == self .clickPos
239245 left = event .button () == Qt .MouseButton .LeftButton
246+ isHyperlink = False
240247 if samePos and left and self .anchor :
241- self .errorHyperlink ()
248+ isHyperlink = self .errorHyperlink ()
242249
243250 self .clickPos = None
244251 self .anchor = None
252+
245253 QApplication .restoreOverrideCursor ()
246- return super (ConsolePrEdit , self ).mouseReleaseEvent (event )
254+ ret = super (ConsolePrEdit , self ).mouseReleaseEvent (event )
255+
256+ # If user clicked a hyperlink, don't put cursor there. It's confusing.
257+ if isHyperlink and self .textCursorPos :
258+ cursor = self .textCursor ()
259+ cursor .setPosition (self .textCursorPos )
260+ self .setTextCursor (cursor )
261+ self .textCursorPos = None
262+
263+ return ret
247264
248265 def keyReleaseEvent (self , event ):
249266 """Override of keyReleaseEvent to determine when to end navigation of
@@ -262,6 +279,7 @@ def errorHyperlink(self):
262279 The text editor defaults to SublimeText3, in the normal install directory
263280 """
264281 window = self .window ()
282+ isHyperlink = False
265283
266284 # Bail if Error Hyperlinks setting is not turned on or we don't have an anchor.
267285 doHyperlink = (
@@ -270,7 +288,7 @@ def errorHyperlink(self):
270288 and self .anchor
271289 )
272290 if not doHyperlink :
273- return
291+ return isHyperlink
274292
275293 # info is a comma separated string, in the form: "filename, workboxIdx, lineNum"
276294 info = self .anchor .split (', ' )
@@ -294,19 +312,21 @@ def errorHyperlink(self):
294312 if not exePath :
295313 msg += "No text editor path defined."
296314 print (msg )
297- return
315+ return isHyperlink
298316 if not os .path .exists (exePath ):
299317 msg += "Text editor executable does not exist: {}" .format (exePath )
300318 print (msg )
301- return
319+ return isHyperlink
302320 if not cmdTempl :
303321 msg += "No text editor Command Prompt command template defined."
304322 print (msg )
305- return
323+ return isHyperlink
306324 if modulePath and not os .path .exists (modulePath ):
307325 msg += "Specified module path does not exist: {}" .format (modulePath )
308326 print (msg )
309- return
327+ return isHyperlink
328+
329+ isHyperlink = bool (modulePath or workboxName )
310330
311331 if modulePath :
312332 # Check if cmdTempl filepaths aren't wrapped in double=quotes to handle
@@ -342,6 +362,8 @@ def errorHyperlink(self):
342362 workbox .__goto_line__ (lineNum )
343363 workbox .setFocus ()
344364
365+ return isHyperlink
366+
345367 def getPrevCommand (self ):
346368 """Find and display the previous command in stack"""
347369 self ._prevCommandIndex -= 1
0 commit comments