I have an NSTextView that uses the find bar ([textView setUsesFindBar:YES];).
I have 2 questions.
-
How do I clear the visual feedback from a find operation?
My problem happens when I programmatically change the content of the textView. The visual feedback for a search operation on the previous content remains after the content change. Obviously these yellow boxes do not apply to the new content so I need a way to clear them when changing the textView content.
Note: I did not implement the NSTextFinderClient protocol because I have a simple textView and the find bar just works without any other effort.
-
How can I send a search string to the find bar?
I found my answers, so for others here’s how to do it.
First you need an instance of NSTextFinder so you can control it. We set that up in code.
First answer: To clear visual feedback I can do either of 2 things. I can just cancel the visual feedback…
Or I can alert NSTextFinder that I’m about to change my textView content…
Second answer: There’s a global NSFindPboard. You can use that to set a search.
There’s a problem though. The actual text field in the find bar does not get updated after that code. I found that if I toggle the first responder then I can get it to update…