Skip to content

Commit

Permalink
Added cursor convenience methods to DTAttributedTextContentView #505
Browse files Browse the repository at this point in the history
  • Loading branch information
odrobnik committed Jul 10, 2013
1 parent 6b4de22 commit d8b1f55
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 0 deletions.
23 changes: 23 additions & 0 deletions Core/Source/DTAttributedTextContentView.h
Original file line number Diff line number Diff line change
Expand Up @@ -339,3 +339,26 @@ typedef NSUInteger DTAttributedTextContentViewRelayoutMask;

@end


/**
Methods for getting cursor position and frame. Those are convenience methods that call through to the layoutFrame property which has the same coordinate system as the receiver.
*/
@interface DTAttributedTextContentView (Cursor)

/**
Determines the closest string index to a point in the receiver's frame.
This can be used to find the cursor position to position an input caret at.
@param point The point
@returns The resulting string index
*/
- (NSInteger)closestCursorIndexToPoint:(CGPoint)point;

/**
The rectangle to draw a caret for a given index
@param index The string index for which to determine a cursor frame
@returns The cursor rectangle
*/
- (CGRect)cursorRectAtIndex:(NSInteger)index;

@end
15 changes: 15 additions & 0 deletions Core/Source/DTAttributedTextContentView.m
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,21 @@ + (Class)layerClass
@end


@implementation DTAttributedTextContentView (Cursor)

- (NSInteger)closestCursorIndexToPoint:(CGPoint)point
{
return [self.layoutFrame closestCursorIndexToPoint:point];
}

- (CGRect)cursorRectAtIndex:(NSInteger)index
{
return [self.layoutFrame cursorRectAtIndex:index];
}

@end


@implementation DTAttributedTextContentView

- (void)setup
Expand Down

0 comments on commit d8b1f55

Please sign in to comment.