예제 #1
0
        void RealtimeEmojiReplace()
        {
            if (!AllowEmojiReplace)
            {
                return;
            }

            if (CaretPos == 0)
            {
                return;
            }

            string lookup = null;

            for (int i = CaretPos - 2; i >= 0; i--)
            {
                var c = Text[i];

                if (char.IsWhiteSpace(c))
                {
                    return;
                }

                if (c == ':')
                {
                    lookup = Text.Substring(i, CaretPos - i);
                    break;
                }

                if (i == 0)
                {
                    return;
                }
            }

            if (lookup == null)
            {
                return;
            }

            var replace = Emoji.FindEmoji(lookup);

            if (replace == null)
            {
                return;
            }

            var lengthDelta = replace.Length - lookup.Length;

            Text      = Text.Replace(lookup, replace);
            CaretPos += lengthDelta;
        }