Re: NSString of selected text in NSTextView
Re: NSString of selected text in NSTextView
- Subject: Re: NSString of selected text in NSTextView
- From: Todd Heberlein <email@hidden>
- Date: Sat, 07 Nov 2009 19:49:10 -0800
[[myTextView string] substringWithRange:[myTextView selectedRange];
(Warning, composed in Mail. Potential thorny issues with text
attachment characters, surrogate pairs, composed characters, marked
text… "the selected text" isn't as simple of a concept as it may
seem.)
Yeah, one of the concerns I had was whether the selected NSRange is
preserved when -string is called. Thats why I was thinking it might be
more robust to extract the RTF and then down convert that to a string
(actually, I may convert it to an C-string) :(.
What I am trying to do is a context sensitive menu, so when a user
right-clicks in the NSTextView and the selected content looks like an
IP address, menu items for IP addresses can be presented, and if the
selected item looks like a file path, menu items for file paths can be
added. Then of course is the user selects one of those menu items, I'm
going to need to go through the steps again to extract the content in
the method.
I just feel this must be a common thing to do (like when menu items
"Search in Google" and "Look up in Dictionary" are added to the
context menu), so I am hoping there is a method that already exists.
Todd
_______________________________________________
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