Re: NSTextView Text Dragging Position (2)
Re: NSTextView Text Dragging Position (2)
- Subject: Re: NSTextView Text Dragging Position (2)
- From: Satoshi Matsumoto <email@hidden>
- Date: Fri, 14 Oct 2005 10:19:04 +0900
on 05.10.14 5:38 AM, Seth Willits at email@hidden wrote:
> Does anyone know how to determine the character positions that text
> was dropped onto an NSTextView? I need to manipulate the string and
> do my own custom insertion but I haven't yet figured out how to find
> the character position to insert the text at.
You can get the dragging character location from NSDraggingInfo.
For example,
- (BOOL)performDragOperation:(id <NSDraggingInfo>)sender
{
NSPoint draggingLocation = [sender draggingLocation];
draggingLocation = [self convertPoint:draggingLocation fromView:nil];
unsigned int characterIndex = [self
characterIndexOfPoint:draggingLocation];
......
}
- (unsigned int)characterIndexOfPoint:(NSPoint)aPoint
{
unsigned int glyphIndex;
NSLayoutManager *layoutManager = [self layoutManager];
float fraction;
NSRange range;
range = [layoutManager glyphRangeForTextContainer:[self textContainer]];
glyphIndex = [layoutManager glyphIndexForPoint:aPoint
inTextContainer:[self textContainer]
fractionOfDistanceThroughGlyph:&fraction];
if( fraction > 0.5 ) glyphIndex++;
if( glyphIndex == NSMaxRange(range) ) return [[self textStorage]
length];
else return [layoutManager characterIndexForGlyphAtIndex:glyphIndex];
}
Satoshi
-----------------------------------------------------
Satoshi Matsumoto <email@hidden>
816-5 Odake, Odawara, Kanagawa, Japan 256-0802
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Cocoa-dev mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden