@@ -9,6 +9,8 @@ import Foundation
99import CodeEditTextView
1010
1111extension FindPanelViewModel {
12+ /// Replace one or all ``findMatches`` with the contents of ``replaceText``.
13+ /// - Parameter all: If true, replaces all matches instead of just the selected one.
1214 func replace( all: Bool ) {
1315 guard let target = target,
1416 let currentFindMatchIndex,
@@ -23,7 +25,7 @@ extension FindPanelViewModel {
2325
2426 var sortedMatches = findMatches. sorted ( by: { $0. location < $1. location } )
2527 for (idx, _) in sortedMatches. enumerated ( ) . reversed ( ) {
26- replaceMatch ( index: idx, target : target , textView: textViewController. textView, matches: & sortedMatches)
28+ replaceMatch ( index: idx, textView: textViewController. textView, matches: & sortedMatches)
2729 }
2830
2931 textViewController. textView. textStorage. endEditing ( )
@@ -38,20 +40,20 @@ extension FindPanelViewModel {
3840
3941 updateMatches ( [ ] )
4042 } else {
41- replaceMatch (
42- index: currentFindMatchIndex,
43- target: target,
44- textView: textViewController. textView,
45- matches: & findMatches
46- )
43+ replaceMatch ( index: currentFindMatchIndex, textView: textViewController. textView, matches: & findMatches)
4744 updateMatches ( findMatches)
4845 }
4946
5047 // Update the emphases
5148 addMatchEmphases ( flashCurrent: true )
5249 }
53-
54- private func replaceMatch( index: Int , target: FindPanelTarget , textView: TextView , matches: inout [ NSRange ] ) {
50+
51+ /// Replace a single match in the text view, updating all other find matches with any length changes.
52+ /// - Parameters:
53+ /// - index: The index of the match to replace in the `matches` array.
54+ /// - textView: The text view to replace characters in.
55+ /// - matches: The array of matches to use and update.
56+ private func replaceMatch( index: Int , textView: TextView , matches: inout [ NSRange ] ) {
5557 let range = matches [ index]
5658 // Set cursor positions to the match range
5759 textView. replaceCharacters ( in: range, with: replaceText)
0 commit comments