Re: [Q] How can one programatically begin a text editing session in a NSTextField?
Re: [Q] How can one programatically begin a text editing session in a NSTextField?
- Subject: Re: [Q] How can one programatically begin a text editing session in a NSTextField?
- From: Eric Gorr <email@hidden>
- Date: Thu, 5 Feb 2009 13:11:37 -0500
On Feb 5, 2009, at 12:39 PM, Eric Gorr wrote:
On Feb 5, 2009, at 12:33 PM, Andy Lee wrote:
On Feb 5, 2009, at 12:17 PM, Eric Gorr wrote:
I wasn't sure what _textField2 was supposed to refer to exactly,
Oops, copy-paste error. :)
so I tried this instead:
[[textField currentEditor] setSelectedRange:NSMakeRange(0, 0)];
Bah, currentEditor is what I was trying to remember.
:-)
So, if you know of an easy way to determine the location in the
string of a NSTextField where a click occurred, I am interested.
This actually turned out to be fairly easy:
NSTextView *currentEditor = (NSTextView*)[textField currentEditor];
NSPoint windowLocation = [theEvent locationInWindow];
NSPoint screenLocation = [[self window]
convertBaseToScreen:windowLocation];
NSUInteger characterIndex = [currentEditor
characterIndexForPoint:screenLocation];
[currentEditor setSelectedRange:NSMakeRange(characterIndex + 1, 0)];
Woo Hoo
_______________________________________________
Cocoa-dev mailing list (email@hidden)
Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden