• 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: Getting at NSTextFinder from text view
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Getting at NSTextFinder from text view


  • Subject: Re: Getting at NSTextFinder from text view
  • From: Martin Hewitson <email@hidden>
  • Date: Mon, 13 Apr 2015 09:31:27 +0200

Hi Shane,

The way I’ve been doing this is to keep hold of my own text finder in my NSTextView subclass:

    self.textFinder = [[NSTextFinder alloc] init];

then to set it up like this:

  [self.textFinder setClient:self];
  [self.textFinder setFindBarContainer:[self enclosingScrollView]];
  [self setUsesFindBar:YES];
  [self setIncrementalSearchingEnabled:YES];

then when I want to switch out the text (because I’m changing the underlying text storage) I do

  [self.textFinder cancelFindIndicator];
  [self.textFinder noteClientStringWillChange];

Unfortunately I still get reports of crashes similar to what you report. I’ve even made a test project that shows that doing this doesn’t fix the problem. On switching the text storage, the find bar stays visible (even though I’m calling -cancelFindIndicator, probably because this isn’t supposed to hide the find bar, and I don’t know how to do that), and hitting enter again to get the next search result shows a false result. If that result would be out of bounds of the new text string, then a crash will happen, of course.

I’m happy to share my test project, if you are interested. And I’d be really happy to hear about a way to deal with this. I’ve been in touch with Apple and even provided my test project, but that was a long time ago, and still the issue remains. So either there is a bug, or I’m doing something wrong in swapping out the text storage for the text view.

Cheers,

Martin



> On 13 Apr 2015, at 04:00, Shane Stanley <email@hidden> wrote:
>
> My document window includes several text views, all with find bars and incremental searching enabled, and searching works as expected. However, if I change the contents of a view via its text storage, and the user is in the middle of a search (that is, the gray overlay is showing with finds highlighted), I get either a crash (out-of-range error) or nonsense highlighted (the same ranges highlighted even though the content differs).
>
> It looks to me like I need to call either -cancelFindIndicator or -noteClientStringWillChange on the text finder before I change the text. But I can't see how I can actually get hold of the frameworks-provided text finder to message it.
>
> I fear I'm missing something simple. Any clues?
>
> --
> Shane Stanley <email@hidden>
> <www.macosxautomation.com/applescript/apps/>
>
>
> _______________________________________________
>
> 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


  • Follow-Ups:
    • Re: Getting at NSTextFinder from text view
      • From: Shane Stanley <email@hidden>
References: 
 >Getting at NSTextFinder from text view (From: Shane Stanley <email@hidden>)

  • Prev by Date: Getting at NSTextFinder from text view
  • Next by Date: Re: Getting at NSTextFinder from text view
  • Previous by thread: Getting at NSTextFinder from text view
  • Next by thread: Re: Getting at NSTextFinder from text view
  • Index(es):
    • Date
    • Thread