bobbylight / RSyntaxTextArea

A syntax highlighting, code folding text editor for Java Swing applications.
BSD 3-Clause "New" or "Revised" License
1.12k stars 259 forks source link

Hyperlinks stopped working with 3.1.0+ #443

Closed ThexXTURBOXx closed 2 years ago

ThexXTURBOXx commented 2 years ago

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 commented 2 years ago

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

ThexXTURBOXx commented 2 years ago

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

bobbylight commented 2 years ago

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.

ThexXTURBOXx commented 2 years ago

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