Dragging caret in NSTextView doesn't match result of characterIndexForPoint

cocoa

Solution

Ok, the solution is to use characterIndexForInsertionAtPoint instead of characterIndexForPoint. Thusly,

NSPoint mouseLocation = [sender draggingLocation];
NSUInteger dropLocation = [self characterIndexForInsertionAtPoint:[self convertPoint:mouseLocation fromView:nil]];

Problem

I'm dragging onto an NSTextView (from a table in another window) and as I drag over the text in the NSTextView a caret is displayed showing the insertion point. There appears to be no way to get the location of this caret and I'm using: ``` NSPoint mouseLocation = [sender draggingLocation]; NSPoint localMouseLocation = [self convertPoint:mouseLocation fromView:nil]; CGFloat fraction = 0.4; NSUInteger dropLocation = [[self layoutManager] characterIndexForPoint:localMouseLocation inTextContainer:[self textContainer] fractionOfDistanceBetweenInsertionPoints:&fraction]; ``` The problem is that sometimes the inserted text is being inserted one character to the left of the displayed caret. I've tried different values for 'fractionOfDistanceBetweenInsertionPoints' without success. Q1. Is there a way to get the position of the dragging caret? Q2. What 'fractionOfDistanceBetweenInsertionPoints' value is Apple using? Q3. Should I be using an alternative approach (drawInsertionPointInRect perhaps)? Thanks.

Original source