I’m afraid I may not be too helpful here because in my case I’m not using an 
NSTextView, rather mine is a custom view that displays text in various ‘cells’ 
so I had to implement the full textFinderClient protocol and build a corpus of 
searchable text for it to query against.

> On 14 Apr 2015, at 07:20, Martin Hewitson <martin.hewit...@aei.mpg.de> wrote:
> 
> Alas, this doesn’t actually help. If I do this, then switch out the text 
> storage, then the very next time the user hits cmd-f the old search results 
> are highlighted again, but of course over the wrong text, and potentially out 
> of range. My impression is that the -cancelFindIndicator doesn’t clear the 
> last search, just removes it from the screen. Then when bringing back the 
> find bar (after a cancel) the old results are assumed still to be ok, rather 
> than being recalculated.

At this point you need to re-cache the data the find bar is using.

In my case, because I’m implementing the NSTextFinderClient protocol, I simply 
rebuild the model that is the store of text to search (an array of dictionaries 
as it happens).  When the text finder asks for its data it is thus correct and 
up to date.

It would seem that in both your cases NSTextView should be fully aware of all 
this by itself.  Perhaps the problem is in switching the NSTextStorage out 
without notifying the text view of the change?  Are you swapping the 
textStorage instance completely?  Perhaps changing it’s content and wrapping 
with editing calls would work? :

    [textStorage beginEditing];
    [textStorage setAttributedString:theNewAttributedString];
    [textStorage endEditing];

Maybe there’s another way to inform the parent textView that it’s content has 
been changed.

Shane, in your case I agree, -noteClientStringWillChange sounds like exactly 
the method that’s needed.  I can’t see how to get to the textView’s textFinder 
either.  You can get to the *findBar* with [[self.textView enclosingScrollView] 
findBarView] but that’s just an NSView and likely to not be helpful.  If you’re 
not creating your own textFinder (and it seems from Martin’s experience that 
even if you do it doesn’t work) then the only thing I can think of is to 
somehow notify the textView that its content has changed and hope and presume 
that it has an internal mechanism for also notifying its textFinder.

Sorry I can’t be more helpful.



_______________________________________________

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