Skip to content

Commit a98f65b

Browse files
committed
Docs
1 parent ef9e244 commit a98f65b

File tree

3 files changed

+17
-10
lines changed

3 files changed

+17
-10
lines changed

Sources/CodeEditSourceEditor/Find/ViewModel/FindPanelViewModel+Find.swift

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,9 @@ import Foundation
99

1010
extension FindPanelViewModel {
1111
// MARK: - Find
12-
12+
13+
/// Performs a find operation on the find target and updates both the ``findMatches`` array and the emphasis
14+
/// manager's emphases.
1315
func find() {
1416
// Don't find if target or emphasisManager isn't ready or the query is empty
1517
guard let target = target, isFocused, !findText.isEmpty else {

Sources/CodeEditSourceEditor/Find/ViewModel/FindPanelViewModel+Replace.swift

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@ import Foundation
99
import CodeEditTextView
1010

1111
extension 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)

Sources/CodeEditSourceEditor/Find/ViewModel/FindPanelViewModel.swift

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ class FindPanelViewModel: ObservableObject {
3535
return mode == .replace ? 54 : 28
3636
}
3737

38+
/// The number of current find matches.
3839
var matchCount: Int {
3940
findMatches.count
4041
}
@@ -66,13 +67,15 @@ class FindPanelViewModel: ObservableObject {
6667

6768
// MARK: - Text Listeners
6869

70+
/// Find target's text content changed, we need to re-search the contents and emphasize results.
6971
@objc private func textDidChange() {
7072
// Only update if we have find text
7173
if !findText.isEmpty {
7274
find()
7375
}
7476
}
7577

78+
/// The contents of the find search field changed, trigger related events.
7679
func findTextDidChange() {
7780
// Check if this update was triggered by a return key without shift
7881
if let currentEvent = NSApp.currentEvent,

0 commit comments

Comments
 (0)