Character at point during perform drag
Character at point during perform drag
- Subject: Character at point during perform drag
- From: Philip Dow <email@hidden>
- Date: Tue, 14 Mar 2006 12:37:22 +0100
There are circumstances in a subclass of nstextview when I need to
override the default performDragOperation: behavior. For instance, I
need to link to files rather than read their contents into the
textview's data, or I need to resize pictures before placing them in
the view.
During a drag, the text view updates what is seems to be a temporary
insertion point. When the drag is performed, calling super's
performDragOperation: ensures that the data is dropped at the correct
location. However, when I need to handle the drag on my own, I have
found that inserting the data at the rangeForUserTextChange point
does not insert it in the location indicated by the drag. Rather, I
must calculate the insertion point myself.
I can do this. The following code works *except* when the drop is to
occur at the very last character of the text view. In this case, the
data is consistently inserted at the second to last character. If the
last character is a newline, and the temporary caret indicates the
drop will occur on this new line, when I handle the drop myself, it
occurs at the end of the line above. Or if the last character is a
period and the caret indicates the drop will occur after it, when I
handle the drop myself, it occurs between the period and the
character before it.
Why is this? Can I edit the following code to get the correct
insertion point even at the last character, or is there a better way
to do this?
- (BOOL)performDragOperation:(id <NSDraggingInfo>)sender {
...
NSPoint mouseLoc = [sender draggingLocation];
NSPoint charLoc = [[self window] convertBaseToScreen:mouseLoc];
int charIndex = [self characterIndexForPoint:charLoc];
[self setSelectedRange:NSMakeRange(charIndex,0)];
...
}
-Phil
_______________________________________________
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