Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Double-clicking a word containing numbers with underscore does not select the whole word #837

Closed
bigDevDe opened this issue Aug 8, 2019 · 2 comments

Comments

@bigDevDe
Copy link

bigDevDe commented Aug 8, 2019

When double clicking "huhu_2" it only selects "huhu" instead of the whole word.

image

Seems to be a problem with the BreakIterator, I found a similar (solved) Issue #197

A workaround or a fix would be great! Thanks!

@Jugen
Copy link
Collaborator

Jugen commented Aug 8, 2019

You can workaround by overriding selectWord() with something like:

private final CodeArea area = new CodeArea()
{
    @Override public void selectWord()
    {
        if ( getLength() == 0 ) return;

        CaretSelectionBind<?,?,?> csb = getCaretSelectionBind();
        int position = csb.getPosition(); 
        
        BreakIterator breakIterator = BreakIterator.getWordInstance();
        breakIterator.setText( getText() );

        breakIterator.preceding( position );
        int start = breakIterator.current();
        
        while ( start > 0 && "_-".indexOf( getText().charAt( start-1 ) ) > -1 )
        {
            if ( --start > 0 && ! breakIterator.isBoundary( start-1 ) )
            {
                breakIterator.preceding( start );
                start = breakIterator.current();
            }
        }
        
        breakIterator.following( position );
        int end = breakIterator.current();
        
        while ( end < getLength() && "_-".indexOf( getText().charAt( end ) ) > -1 )
        {
            if ( ++end < getLength() && ! breakIterator.isBoundary( end+1 ) )
            {
                breakIterator.following( end );
                end = breakIterator.current();
            }
            // For some reason single digits aren't picked up so ....
            else if ( Character.isDigit( getText().charAt( end ) ) )
            {
                end++;
            }
        }
        
        csb.selectRange( start, end );
    }
};

@Jugen
Copy link
Collaborator

Jugen commented Aug 29, 2019

This is now built into the latest release of CodeArea in RichTextFX 0.10.2

@Jugen Jugen closed this as completed Aug 29, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants