Re: Incremental parsing/highlighting in an NSTextView via shouldChangeTextInRange delegate method
Re: Incremental parsing/highlighting in an NSTextView via shouldChangeTextInRange delegate method
- Subject: Re: Incremental parsing/highlighting in an NSTextView via shouldChangeTextInRange delegate method
- From: Ross Carter <email@hidden>
- Date: Fri, 20 May 2011 13:19:44 -0400
On May 19, 2011, at 1:23 PM, Martin Schürrer wrote:
> I want to highlight @mentions, #hashtags and links in an NSTextView as
> the user types. I've been thinking I'd implement this via the
> shouldChangeTextInRange delegate method.
>
> My plan is as follows:
> I'm going to construct the new string (via
> stringByReplacingCharactersInRange:affectedCharRange
> withString:replacementString) and check the word (chain of chars
> separated by spaces on both ends) that's changed and highlight only
> this word.
I don't understand exactly what you are trying to do.
When you say "highlight," do you mean you want to change the text attributes of the word the user is currently typing?
If the answer is yes, why are you changing the contents of the string? I don't understand what you are replacing with what.
Generally, -doubleClickAtIndex: is the best way to get the range of a word (or "linguistic unit"). Looking for space characters can fail for any number of reasons (for example, some writing systems do not separate words with spaces).
NSTextView can already handle links._______________________________________________
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