• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: Extending range of current edit in textView?
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Extending range of current edit in textView?


  • Subject: Re: Extending range of current edit in textView?
  • From: Eric Wang <email@hidden>
  • Date: Thu, 03 Jul 2003 13:31:58 -0400

on 7/3/03 12:47 PM, Matt Gemmell at email@hidden wrote:

> Hi there folks,
>
> I need to alter the attributes of the text in an NSTextView as the user
> types. I'm receiving -textStorageWillProcessEditing: (having registered
> as the delegate of my textView's textStorage), and I plan to perform my
> processing in there.
>
> I'm looking for pointers as to how to go about determining which range
> of text to inspect, and potentially alter the attributes of. I'm aware
> that I can ask my textStorage for its -editedRange, but I need to extend
> this range (in both directions) outwards to the nearest whitespace
> character. So, if my edit affects the text in [] below:
>
> Email us at us@[company].com today!
>
> Then I need to programmatically obtain the range of "email@hidden".
> I'm aware that I can use an NSScanner to trivially extend the range
> forward in this way, using the -whitespaceAndNewlineCharacterSet.
>
> The question is, how should I go about "scanning backwards", as it were?
> From reading the docs, NSScanner doesn't seem to be able to go in
> reverse, though I do note the -setLocation: method. I could just
> repeatedly check the previous character until I find a member of the
> whitespaceAndNewlineCharacterSet, but that seems as though it might
> potentially be slow.
>
> I also considered using my textView's layoutManager, but obtaining a
> line-fragment for the editedRange is only of marginal use to me, since
> I'd still need to check if it contained appropriate delimiters for my
> purposes. I'd be more interested in actual lines (return-delimited),
> which I could then at least feed into an NSScanner easily enough.
>
> Any advice? To reiterate: upon receiving notification that my textView
> has been edited, I require to determine the range which is the
> editedRange extended outwards (back and forward) to any whitespace or
> newline characters. Thanks for any response!
>
> Cheers,
> -Matt


Hi Matt,

You might want to try NSString's -rangeOfCharacterFromSet:options:range:
method, passing in [NSCharacterSet whitespaceAndNewlineCharacterSet] for the
character set, NSBackwardsSearch (if you are extending the edited range
backwards) for options:, and the edited range for range:.

Eric Wang
_______________________________________________
cocoa-dev mailing list | email@hidden
Help/Unsubscribe/Archives: http://www.lists.apple.com/mailman/listinfo/cocoa-dev
Do not post admin requests to the list. They will be ignored.

  • Prev by Date: Re: Obj-C language question: C function within @implementation
  • Next by Date: Static libraries
  • Previous by thread: Re: Strong language about Cocoa and Qt
  • Next by thread: Static libraries
  • Index(es):
    • Date
    • Thread