Example #1
0
        private bool removeCharacterOrSelection(bool sound = true)
        {
            if (InternalText.Length == 0)
            {
                return(false);
            }
            if (selectionLength == 0 && selectionLeft == 0)
            {
                return(false);
            }

            int count = MathHelper.Clamp(selectionLength, 1, InternalText.Length);
            int start = MathHelper.Clamp(selectionLength > 0 ? selectionLeft : selectionLeft - 1, 0, InternalText.Length - count);

            if (count == 0)
            {
                return(false);
            }

            if (sound)
            {
                audio.Sample.Get(@"Keyboard/key-delete")?.Play();
            }

            foreach (var d in textFlow.Children.Skip(start).Take(count).ToArray()) //ToArray since we are removing items from the children in this block.
            {
                textFlow.Remove(d);

                textContainer.Add(d);
                d.FadeOut(200);
                d.MoveToY(d.DrawSize.Y, 200, EasingTypes.InExpo);
                d.Expire();
            }

            InternalText = InternalText.Remove(start, count);

            if (selectionLength > 0)
            {
                selectionStart = selectionEnd = selectionLeft;
            }
            else
            {
                selectionStart = selectionEnd = selectionLeft - 1;
            }

            cursorAndLayout.Invalidate();
            return(true);
        }