From 80ece8ed1fe07450b4bdd28be42fcbd0c1c42401 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Simon=20St=C3=B8vring?= Date: Sun, 25 Sep 2022 15:33:25 +0200 Subject: [PATCH] Adds code snippet to search(for:replacingMatchesWith:) --- Sources/Runestone/TextView/Core/TextView.swift | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/Sources/Runestone/TextView/Core/TextView.swift b/Sources/Runestone/TextView/Core/TextView.swift index 3d2ed9b1b..08a7b30b7 100644 --- a/Sources/Runestone/TextView/Core/TextView.swift +++ b/Sources/Runestone/TextView/Core/TextView.swift @@ -899,7 +899,17 @@ open class TextView: UIScrollView { /// Search for the specified query and return results that take a replacement string into account. /// - /// When searching for a regular expression this function will perform pattern matching and take matched groups into account in the returned results. + /// When searching for a regular expression this function will perform pattern matching and take the matched groups into account in the returned results. + /// + /// The code below examplifies how the returned search results can be used to perform a replace operation. + /// + /// ```swift + /// let query = SearchQuery(text: "foo", matchMethod: .contains, isCaseSensitive: false) + /// let results = textView.search(for: query, replacingMatchesWith: "bar") + /// let replacements = results.map { BatchReplaceSet.Replacement(range: $0.range, text: $0.replacementText) } + /// let batchReplaceSet = BatchReplaceSet(replacements: replacements) + /// textView.replaceText(in: batchReplaceSet) + /// ``` /// /// - Parameters: /// - query: Query to find matches for.