Skip to content

Commit

Permalink
Fix #443: LinkGenerators stopped working unless a HyperlinkListener w…
Browse files Browse the repository at this point in the history
…as registered on the text area. We must make sure to execute LinkGeneratorResults on any click event, whether or not a HyperlinkListener is registered
  • Loading branch information
bobbylight committed Sep 25, 2022
1 parent 0547761 commit 3cfacc1
Showing 1 changed file with 7 additions and 9 deletions.
Expand Up @@ -910,23 +910,21 @@ private void fireActiveLineRangeEvent(int min, int max) {
*/
protected void fireHyperlinkUpdate(HyperlinkEvent.EventType type) {

HyperlinkEvent e = null;
// Fix #443: Don't lazily create the event as LinkGenerators may
// handle the click themselves. We want such handling to occur
// even if no HyperlinkListeners are attached.
HyperlinkEvent e = createHyperlinkEvent(type);
if (e == null) {
return; // No linkable text under caret, or handled by LinkGenerator
}

// Guaranteed to return a non-null array
Object[] listeners = listenerList.getListenerList();

// Process the listeners last to first, notifying
// those that are interested in this event
for (int i = listeners.length-2; i>=0; i-=2) {

if (listeners[i]==HyperlinkListener.class) {

if (e == null) {
e = createHyperlinkEvent(type);
if (e == null) {
return; // No linkable text under the caret
}
}
((HyperlinkListener)listeners[i+1]).hyperlinkUpdate(e);
}
}
Expand Down

0 comments on commit 3cfacc1

Please sign in to comment.