Last active
March 2, 2024 04:36
-
-
Save Oil3/82fb57a47adcc7c1a81db69f115c3b83 to your computer and use it in GitHub Desktop.
WKWebView search / find for MacOS swift
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//Actually it is built-in for Mac as well, no need of 3 pages of Js, | |
//In the contentview: | |
@State private var searchText = "" | |
//inside its navigationsplitview/stack the automatic field | |
.searchable(text: $searchText) | |
//In the view: | |
@Binding var searchText: String | |
if !searchText.isEmpty { | |
let findConfiguration = WKFindConfiguration() | |
findConfiguration.caseSensitive = false | |
findConfiguration.wraps = true | |
nsView.find(searchText, configuration: findConfiguration) { result in | |
// Handle the results of the search | |
print("Matches found: \(result)") | |
} | |
//that's it, need activate cmd+F and cmd+G and perfect |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment