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)); }
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)); }
public static IndexedPosition GetPosition (int index) { IndexedPosition result; if (!indexes.TryGetValue (index, out result)) { result = new IndexedPosition (index); indexes [index] = result; } return result; }
public static IndexedPosition GetPosition(int index) { IndexedPosition result; if (!indexes.TryGetValue(index, out result)) { result = new IndexedPosition(index); indexes [index] = result; } return(result); }
RectangleF CaretRect(UITextPosition position) { // FIXME: the Objective-C code doesn't get a null position // 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 IndexedPosition pos = (IndexedPosition)(position ?? IndexedPosition.GetPosition(0)); // Get caret rect from underlying SimpleCoreTextView RectangleF rect = textView.CaretRect(pos.Index); // Convert rect to our view coordinates return(ConvertRectFromView(rect, textView)); }
IndexedPosition GetPosition(UITextPosition position, int offset) { // Generate IndexedPosition instance, and increment index by offset IndexedPosition pos = (IndexedPosition)position; int end = pos.Index + offset; // Verify position is valid in document if (end > text.Length || end < 0) { return(null); } return(IndexedPosition.GetPosition(end)); }
NSComparisonResult ComparePosition(UITextPosition position, UITextPosition other) { IndexedPosition pos = (IndexedPosition)position; IndexedPosition o = (IndexedPosition)other; // For this sample, we simply compare position index values if (pos.Index == o.Index) { return(NSComparisonResult.Same); } else if (pos.Index < o.Index) { return(NSComparisonResult.Ascending); } else { return(NSComparisonResult.Descending); } }
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)); }
IndexedPosition GetPosition(UITextPosition position, UITextLayoutDirection direction, int offset) { // Note that this sample assumes LTR text direction IndexedPosition pos = (IndexedPosition)position; int newPos = pos.Index; switch (direction) { case UITextLayoutDirection.Right: newPos += offset; break; case UITextLayoutDirection.Left: newPos -= offset; break; case UITextLayoutDirection.Up: case UITextLayoutDirection.Down: // This sample does not support vertical text directions break; } // Verify new position valid in document if (newPos < 0) { newPos = 0; } if (newPos > text.Length) { newPos = text.Length; } return(IndexedPosition.GetPosition(newPos)); }
int GetOffset (IndexedPosition @from, IndexedPosition toPosition) { return @from.Index - toPosition.Index; }
int GetOffset(IndexedPosition @from, IndexedPosition toPosition) { return(@from.Index - toPosition.Index); }