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

emoji:TextBox.TextChanged Not working as expected #64

Open
Hakoyu opened this issue Nov 30, 2022 · 1 comment
Open

emoji:TextBox.TextChanged Not working as expected #64

Hakoyu opened this issue Nov 30, 2022 · 1 comment

Comments

@Hakoyu
Copy link

Hakoyu commented Nov 30, 2022

emoji:TextBox.TextChanged And emoji:RichTextBox.TextChanged
I want to get the input characters in the TextChanged event, but they are always lagging.
Unlike the vanilla TextBox which can get it immediately.

@samhocevar
Copy link
Owner

Can you be more specific about what you mean by lagging? Is there a delay before the event is triggered, or are the characters wrong?

This is how I would do it with RichTextBox:

EmojiRichTextBox.TextChanged += (o, e) =>
{
    System.Diagnostics.Debug.WriteLine($"TextChanged fired! ({e.Changes.Count} changes)");

    var doc = (e.Source as Emoji.Wpf.RichTextBox).Document;
    foreach (var c in e.Changes)
    {
        var range = new System.Windows.Documents.TextRange(
            doc.ContentStart.GetPositionAtOffset(c.Offset),
            doc.ContentStart.GetPositionAtOffset(c.Offset + c.AddedLength));
        var text = range.Text;

        System.Diagnostics.Debug.WriteLine($"  [{c.Offset}] +{c.AddedLength} -{c.RemovedLength} -> '{text}'");
    }
};

And typing in the RichTextBox gives:

TextChanged fired! (1 changes)
  [2] +1 -0 -> 'H'
TextChanged fired! (1 changes)
  [3] +1 -0 -> 'i'
TextChanged fired! (1 changes)
  [4] +1 -0 -> '♥'

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants