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.
textFinder = [[NSTextFinder alloc] init];
[textFinder setClient:textView];
[textFinder setFindBarContainer:[textView enclosingScrollView]];
[textView setUsesFindBar:YES];
[textView setIncrementalSearchingEnabled:YES];
First answer: To clear visual feedback I can do either of 2 things. I can just cancel the visual feedback...
[textFinder cancelFindIndicator];
Or I can alert NSTextFinder that I'm about to change my textView content...
[textFinder noteClientStringWillChange];
Second answer: There's a global NSFindPboard. You can use that to set a search.
// change the NSFindPboard NSPasteboardTypeString
NSPasteboard* pBoard = [NSPasteboard pasteboardWithName:NSFindPboard];
[pBoard declareTypes:[NSArray arrayWithObjects:NSPasteboardTypeString, NSPasteboardTypeTextFinderOptions, nil] owner:nil];
[pBoard setString:@"new search" forType:NSStringPboardType];
NSDictionary* options = [NSDictionary dictionaryWithObjectsAndKeys:[NSNumber numberWithBool:YES], NSTextFinderCaseInsensitiveKey, [NSNumber numberWithInteger:NSTextFinderMatchingTypeContains], NSTextFinderMatchingTypeKey, nil];
[pBoard setPropertyList:options forType:NSPasteboardTypeTextFinderOptions];
// put the new search string in the find bar
[textFinder cancelFindIndicator];
[textFinder performAction:NSTextFinderActionSetSearchString];
[textFinder performAction:NSTextFinderActionShowFindInterface]; // make sure the find bar is showing
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...
[myWindow makeFirstResponder:outlineView];
[myWindow makeFirstResponder:textView];
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…