public bool ShouldChangeCharacters(UITextView textView, NSRange range, string text)
            {
                if (!isPressingBackspace(range, text))
                {
                    return(true);
                }

                var cursorPosition = range.Location;
                var attrs          = textView.AttributedText.GetAttributes(cursorPosition, out var attrRange);

                var isDeletingProject = attrs.ObjectForKey(TimeEntryTagsTextView.RoundedBackground) != null;

                if (isDeletingProject)
                {
                    ProjectDeleted.Raise(this);
                    return(false);
                }

                var isDeletingTag = attrs.ObjectForKey(TimeEntryTagsTextView.RoundedBorders) != null;

                if (isDeletingTag)
                {
                    TagDeleted?.Invoke(this, new TagDeletedEventArgs(cursorPosition));
                    return(false);
                }

                return(true);
            }
예제 #2
0
        public override bool ShouldChangeText(UITextView textView, NSRange range, string text)
        {
            if (isTypingMultistageCharacter(range, text))
            {
                IsWritingMultistageCharacter.Raise(this);
                return(true);
            }

            if (!isPressingBackspace(range, text))
            {
                return(true);
            }

            var cursorPosition = range.Location;
            var attrs          = textView.AttributedText.GetAttributes(cursorPosition, out var attrRange);

            var isDeletingProject = attrs.ObjectForKey(TokenExtensions.Project) != null;

            if (isDeletingProject)
            {
                ProjectDeleted.Raise(this);
                return(false);
            }

            var tagIndex      = attrs.ObjectForKey(TokenExtensions.TagIndex) as NSNumber;
            var isDeletingTag = tagIndex != null;

            if (isDeletingTag)
            {
                TagDeleted?.Invoke(this, new TagDeletedEventArgs((int)cursorPosition, tagIndex.Int32Value));
                return(false);
            }

            return(true);
        }
예제 #3
0
        public void BeforeTextChanged(ICharSequence sequence, int start, int count, int after)
        {
            var isDeleting = count > after;
            if (!isDeleting) return;

            var spannable = sequence as SpannableStringBuilder;
            var deletedSpan = spannable.GetSpans(start, start, Class.FromType(typeof(TokenSpan))).LastOrDefault();
            if (deletedSpan == null) return;

            if (deletedSpan is ProjectTokenSpan)
            {
                ProjectDeleted?.Raise(this);
            }
            else if (deletedSpan is TagsTokenSpan tagSpan)
            {
                TagDeleted?.Invoke(this, new TagDeletedEventArgs(start, tagSpan.TagIndex));
            }
        }