Skip to content

Commit

Permalink
Support Find&Replace
Browse files Browse the repository at this point in the history
  • Loading branch information
krzyzanowskim committed Apr 16, 2022
1 parent da5e436 commit 3a2b052
Showing 1 changed file with 16 additions and 0 deletions.
16 changes: 16 additions & 0 deletions Sources/STTextView/STTextFinderClient.swift
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,21 @@ final class STTextFinderClient: NSObject, NSTextFinderClient {
false
}

func replaceCharacters(in range: NSRange, with string: String) {
guard let textContentManager = textContentManager,
let textRange = NSTextRange(range, in: textContentManager)
else {
return
}

textView?.willChangeText()
textView?.replaceCharacters(in: textRange, with: string)
}

func didReplaceCharacters() {
textView?.didChangeText()
}

public var firstSelectedRange: NSRange {
guard let firstTextSelectionRange = textView?.textLayoutManager.textSelections.first?.textRanges.first,
let textContentManager = textContentManager else {
Expand Down Expand Up @@ -74,6 +89,7 @@ final class STTextFinderClient: NSObject, NSTextFinderClient {
else {
return
}

textView?.scrollToSelection(NSTextSelection(range: textRange, affinity: .downstream, granularity: .character))
}

Expand Down

0 comments on commit 3a2b052

Please sign in to comment.