picoe / Eto

Cross platform GUI framework for desktop and mobile applications in .NET
Other
3.64k stars 330 forks source link

RichTextArea SelectedText empty on OnMouseDoubleClick #1504

Open LaraSQP opened 4 years ago

LaraSQP commented 4 years ago

When double-clicking on a word, it becomes highlighted.

However, SelectedText is empty in OnMouseDoubleClick

protected override void OnMouseDoubleClick( MouseEventArgs e )
{
    base.OnMouseDoubleClick( e );

    if( SelectedText == "" )
    {
        var text = "SelectedText only contains the selected text after this call";
    }
    else
    {
        // Code never reaches here
    }
}

A workaround is to use:

protected override void OnMouseDoubleClick( MouseEventArgs e )
{
    base.OnMouseDoubleClick( e );

    string DELIMITERS = " \n\r\"',.<>/?;:\\|]}{[`~!@#$%^&*()_=+/";
    var start = CaretIndex;
    var end   = CaretIndex;
    var last  = Text.Length;

    while( start > 0
           && DELIMITERS.IndexOf( Text[start] ) == -1 )
    {
        start--;
    }

    while( end < last
           && DELIMITERS.IndexOf( Text[end] ) == -1 )
    {
        end++;
    }

    if( start < end )
    {
        var selectedText = Text.Substring( start, end - start );
    }
}

Darn ugly thing.

cwensley commented 4 years ago

Hey @LaraSQP, what platform(s) have you tested?

LaraSQP commented 4 years ago

No testing. Just built on Windows. I do not have a Mac, thus the question.

cwensley commented 4 years ago

WinForms or WPF?

LaraSQP commented 4 years ago

We are talking on two threads and got confused.

This code works in Windows and Linux using Eto.Forms 2.5.0-rc4

I'm ashamed to say I have no idea if it uses WinForms or WPF.

cwensley commented 4 years ago

@LaraSQP no problem, it's probably WPF if you're using the default projects.

LaraSQP commented 4 years ago

It is WPF, I can see the dependency now.