RSyntaxTextArea icon indicating copy to clipboard operation
RSyntaxTextArea copied to clipboard

Hyperlinks stopped working with 3.1.0+

Open ThexXTURBOXx opened this issue 2 years ago • 2 comments

Description Using RSTA 3.0.8, hyperlinks in Luyten were working properly. However, when updating to 3.1.0 (or even 3.2.0), using the same code, they are not working correctly anymore.

Steps to Reproduce Specific steps to reproduce the behavior:

  1. Add a LinkGenerator to a RSyntaxTextArea and enable hyperlinks
  2. Click on a hyperlink

Expected behavior The LinkGeneratorResult#execute function should be executed

Actual behavior The LinkGeneratorResult#execute function is not executed in RSTA >=3.1.0

Java version Tested with Java 8 and Java 17

Additional context From what I can gather using some debugging code, RSyntaxTextArea#hoveredOverLinkOffset gets reset to -1 when the hyperlink is clicked, probably through RSyntaxTextArea#stopScanningForLinks (however I am not sure!). Because of this, RSyntaxTextAreaMutableCaretEvent#mouseClicked will not fire the ACTIVATED event. I am unsure if I am correct, but I think, this is what's going wrong there. Relevant code can be found here: https://github.com/ThexXTURBOXx/Luyten/blob/main/src/main/java/us/deathmarine/luyten/OpenFile.java#L131

ThexXTURBOXx avatar Apr 06 '22 10:04 ThexXTURBOXx

After looking through the existing issues, I noticed that #441 looks very much just like this one right here. Maybe they are related?

ThexXTURBOXx avatar Apr 06 '22 10:04 ThexXTURBOXx

Adding an empty Hyperlink listener fixes the issue. Thus, the issue lies most likely in this change: https://github.com/bobbylight/RSyntaxTextArea/commit/9bc9f187b84e3fad5000970267360bf843d422bb#diff-04814d39a10acb9fcadce1be9b81a60c97ea2070b99a3af1ff6bbabc0daa2ab7R926

ThexXTURBOXx avatar Apr 06 '22 10:04 ThexXTURBOXx

Better late than never! Thanks @ThexXTURBOXx ! You hit the nail on the head. That code was lazily creating the HyperlinkEvent only if there were HyperlinkListeners registered, but that caused LinkGeneratorResults to not be executed. It wasn't taking into account the contract that they could handle click events themselves. The fix was simply to not lazily evaluate the LinkGeneratorResult.

bobbylight avatar Sep 25 '22 17:09 bobbylight

Thank you very much for the update and the fix! :)

ThexXTURBOXx avatar Sep 25 '22 19:09 ThexXTURBOXx