Re: How is "Apple + Ctrl + D" implemented?
Re: How is "Apple + Ctrl + D" implemented?
- Subject: Re: How is "Apple + Ctrl + D" implemented?
- From: Graham Cox <email@hidden>
- Date: Mon, 28 Apr 2008 20:36:32 +1000
Bear in mind that the question "what is a word?" is far from trivial
to universally answer. So in fact determining the boundaries of a word
can be complex. As far as I can glean from the docs, this job falls to
NSTypesetter, though there isn't an obvious method that simply returns
a word.
What could be easier is to convert the glyph index to a character
index (NSLayoutManager's characterIndexForGlyphAtIndex: will do that
particular trick) and perform your own search forward and backward
from that character in the string, looking for whatever it is that you
think delimits a word.
That said I'm surprised there isn't *something* that will do this,
since e.g. double-clicking in NSTextView will select a word. I've
probably just missed it myself.
G.
On 28 Apr 2008, at 8:06 pm, Ying Bian wrote:
Graham,
Thanks for your reply! But how can I "find the range of the word"
given
the glyph index? I just can not find an API doing so.
So I don't think this is the underlying implementation. Any comments
from others?
On Mon, Apr 28, 2008 at 2:51 PM, Graham Cox <email@hidden>
wrote:
I imagine it uses some API such as NSLayoutManager's:
- (NSUInteger)glyphIndexForPoint:(NSPoint)point
inTextContainer:(NSTextContainer *)container
fractionOfDistanceThroughGlyph:(CGFloat *)partialFraction
One you have the glyph index you can find the range of the word it
belongs
to.
One you have the string of the word it belongs to, you can look it
up in
dictionary.app using the Application Services API.
hth, though I am guessing to some extent.
G.
--
B.Y.
_______________________________________________
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
_______________________________________________
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