How to I highlight search results in a webview like Safari and NSTextView showFindIndicatorForRange:

前端 未结 3 936
遇见更好的自我
遇见更好的自我 2021-01-02 12:00

In Safari, and in an NSTextView on OSX, search results can be highlighted with a bright yellow box that has a little animated pop. Is there any way to do this in a webview

3条回答
  •  时光说笑
    2021-01-02 12:39

    Take a look at this open source WebView subclass (MIT License) that incorporates NSTextFinder support:

    https://github.com/shc-vj/SHCWebView

    as well as the WebKit source itself for its MiniBrowser test app:

    https://github.com/WebKit/webkit/blob/master/Tools/MiniBrowser/mac/WK2BrowserWindowController.m

    The MiniBrowser's window controller implements NSTextFinderBarContainer so it doesn't have to put its WebView inside an otherwise superfluous scrollview for the find bar to work.

提交回复
热议问题