emoji.wpf icon indicating copy to clipboard operation
emoji.wpf copied to clipboard

emoji:TextBox.TextChanged Not working as expected

Open Hakoyu opened this issue 1 year ago • 1 comments

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.

Hakoyu avatar Nov 30 '22 10:11 Hakoyu

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 -> '♥'

samhocevar avatar Jan 03 '23 16:01 samhocevar