Skip to content

Commit

Permalink
Adds code snippet to search(for:replacingMatchesWith:)
Browse files Browse the repository at this point in the history
  • Loading branch information
simonbs committed Sep 25, 2022
1 parent d34d0d9 commit 80ece8e
Showing 1 changed file with 11 additions and 1 deletion.
12 changes: 11 additions & 1 deletion Sources/Runestone/TextView/Core/TextView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down

0 comments on commit 80ece8e

Please sign in to comment.