RSyntaxTextArea icon indicating copy to clipboard operation
RSyntaxTextArea copied to clipboard

LinkGenerator enhancement

Open mgarin opened this issue 11 years ago • 2 comments

To provide LinkGenerator you should code something like this:

editor.setLinkGenerator ( new LinkGenerator ()
{
    @Override
    public LinkGeneratorResult isLinkAtOffset ( final RSyntaxTextArea rSyntaxTextArea, final int i )
    {
        return new LinkGeneratorResult ()
        {
            @Override
            public HyperlinkEvent execute ()
            {
                // Some execution here 
                return new HyperlinkEvent ( this, HyperlinkEvent.EventType.EXITED, null );
            }

            @Override
            public int getSourceOffset ()
            {
                // Link beginning offset
                return 0;
            }
        };
    }
} );

This is pretty smooth and convenient way.

But there are cases when i want to specify hyperlink exact length. This cannot be done at the moment because editor decides where the link ends (using the provided source offset i guess).

Could you provide an additional method in LinkGeneratorResult that would return hyperlink length? Basically, something like this:

editor.setLinkGenerator ( new LinkGenerator ()
{
    @Override
    public LinkGeneratorResult isLinkAtOffset ( final RSyntaxTextArea rSyntaxTextArea, final int i )
    {
        return new LinkGeneratorResult ()
        {
            ...

            @Override
            public int getSourceLength ()
            {
                // Link length
                return 0;
            }
        };
    }
} );

Or does that interfere with your vision of this feature somehow?

mgarin avatar Feb 12 '14 15:02 mgarin

The problem with this is that links are supported in RSTA only at the Token level; links aren't supported for arbitrary character ranges. The fact that you can provide a start offset, and not Token, makes this non-obvious, but it is the case.

And links are supported only at the Token level because that's how RSTA is painted - one token at a time. If we supported links that spanned tokens (or were regions of a single token), we'd have to support breaking up/merging tokens at render time. Or something more sophisticated than that.

This may happen in the future, but I'm not sure it will be any time soon.

bobbylight avatar Feb 13 '14 05:02 bobbylight

I see, thanks for the explanation :)

mgarin avatar Feb 13 '14 06:02 mgarin