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 <sstan...@myriad-com.com.au> 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 <sstan...@myriad-com.com.au>
> <www.macosxautomation.com/applescript/apps/>
> 
> 
> _______________________________________________
> 
> Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)
> 
> 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:
> https://lists.apple.com/mailman/options/cocoa-dev/martin.hewitson%40aei.mpg.de
> 
> This email sent to martin.hewit...@aei.mpg.de


_______________________________________________

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

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:
https://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com

Reply via email to