예제 #1
0
        IndexedPosition GetPosition(UITextRange range, UITextLayoutDirection direction)
        {
            // Note that this sample assumes LTR text direction
            IndexedRange r   = (IndexedRange)range;
            int          pos = r.Range.Location;

            // For this sample, we just return the extent of the given range if the
            // given direction is "forward" in a LTR context (UITextLayoutDirectionRight
            // or UITextLayoutDirectionDown), otherwise we return just the range position
            switch (direction)
            {
            case UITextLayoutDirection.Up:
            case UITextLayoutDirection.Left:
                pos = r.Range.Location;
                break;

            case UITextLayoutDirection.Right:
            case UITextLayoutDirection.Down:
                pos = r.Range.Location + r.Range.Length;
                break;
            }

            // Return text position using our UITextPosition implementation.
            // Note that position is not currently checked against document range.
            return(IndexedPosition.GetPosition(pos));
        }
예제 #2
0
        void ReplaceRange(UITextRange range, string text)
        {
            IndexedRange r = (IndexedRange)range;
            NSRange      selectedNSRange = textView.SelectedTextRange;

            // Determine if replaced range intersects current selection range
            // and update selection range if so.
            if (r.Range.Location + r.Range.Length <= selectedNSRange.Location)
            {
                // This is the easy case.
                selectedNSRange.Location -= (r.Range.Length - text.Length);
            }
            else
            {
                // Need to also deal with overlapping ranges.  Not addressed
                // in this simplified sample.
            }

            // Now replace characters in text storage
            this.text.Remove(r.Range.Location, r.Range.Length);
            this.text.Insert(r.Range.Location, text);

            // Update underlying SimpleCoreTextView
            textView.Text = this.text.ToString();
            textView.SelectedTextRange = selectedNSRange;
        }
예제 #3
0
        IndexedRange GetTextRange(UITextPosition fromPosition, UITextPosition toPosition)
        {
            // Generate IndexedPosition instances that wrap the to and from ranges
            IndexedPosition @from = (IndexedPosition)fromPosition;
            IndexedPosition @to   = (IndexedPosition)toPosition;
            NSRange         range = new NSRange(Math.Min(@from.Index, @to.Index), Math.Abs(to.Index - @from.Index));

            return(IndexedRange.GetRange(range));
        }
예제 #4
0
        RectangleF FirstRect(UITextRange range)
        {
            // FIXME: the Objective-C code doesn't get a null range
            // This is the reason why we don't get the autocorrection suggestions
            // (it'll just autocorrect without showing any suggestions).
            // Possibly due to http://bugzilla.xamarin.com/show_bug.cgi?id=265
            IndexedRange r = (IndexedRange)(range ?? IndexedRange.GetRange(new NSRange(0, 1)));
            // Use underlying SimpleCoreTextView to get rect for range
            RectangleF rect = textView.FirstRect(r.Range);

            // Convert rect to our view coordinates
            return(ConvertRectFromView(rect, textView));
        }
예제 #5
0
        public static IndexedRange GetRange(NSRange theRange)
        {
            IndexedRange result;

            if (theRange.Location == NSRange.NotFound)
            {
                return(null);
            }

            if (!ranges.TryGetValue(theRange, out result))
            {
                result       = new IndexedRange();
                result.Range = new NSRange(theRange.Location, theRange.Length);
            }
            return(result);
        }
예제 #6
0
        IndexedRange GetCharacterRange(UITextPosition position, UITextLayoutDirection direction)
        {
            // Note that this sample assumes LTR text direction
            IndexedPosition pos    = (IndexedPosition)position;
            NSRange         result = new NSRange(pos.Index, 1);

            switch (direction)
            {
            case UITextLayoutDirection.Up:
            case UITextLayoutDirection.Left:
                result = new NSRange(pos.Index - 1, 1);
                break;

            case UITextLayoutDirection.Right:
            case UITextLayoutDirection.Down:
                result = new NSRange(pos.Index, 1);
                break;
            }

            // Return range using our UITextRange implementation
            // Note that range is not currently checked against document range.
            return(IndexedRange.GetRange(result));
        }
예제 #7
0
        string TextInRange(UITextRange range)
        {
            IndexedRange r = (IndexedRange)range;

            return(text.ToString().Substring(r.Range.Location, r.Range.Length));
        }