I'm trying to get a macOS WKWebView to support a standard find bar.
I had hoped that, since NSScrollView supports NSTextFinderBarContainer this might be easy, but it looks like webView.enclosingScrollView returns nil and webView.scrollView doesn't exist on macOS. I suspect it's because WKWebView is using a custom scrolling/caching solution.
However, following the code from WK2WebDocumentController.m I've made some progress. I can now show the find bar, perform a search, see the highlighted regions in the results, and even click the next button to jump to subsequent finds.
But it doesn't auto-scroll to move to the next occurrence if it's offscreen. And if you scroll manually then the highlights aren't getting regenerated so you have ghost "holes" in the results and searching seems broken.
I've tried observing NSViewBoundsDidChangeNotification and NSViewFrameDidChangeNotification for various views and then calling textFinder's setFindIndicatorNeedsUpdate:YES but that doesn't fix the issue. I think the problem is I can't access the WKWebView's scrollview or clipview reference so I can't listen to it.
Does anyone have this working? I feel like I'm so close!
Oh, I'm targetting Mojave and Catalina.
Thanks!