@@ -88,54 +88,69 @@ extension FindViewController: FindPanelDelegate {
88
88
self . replaceText = text
89
89
}
90
90
91
+ private func flashCurrentMatch( emphasisManager: EmphasisManager , textViewController: TextViewController ) {
92
+ let newActiveRange = findMatches [ currentFindMatchIndex]
93
+ emphasisManager. removeEmphases ( for: EmphasisGroup . find)
94
+ emphasisManager. addEmphasis (
95
+ Emphasis (
96
+ range: newActiveRange,
97
+ style: . standard,
98
+ flash: true ,
99
+ inactive: false ,
100
+ selectInDocument: true
101
+ ) ,
102
+ for: EmphasisGroup . find
103
+ )
104
+ }
105
+
91
106
func findPanelPrevButtonClicked( ) {
92
107
guard let textViewController = target as? TextViewController ,
93
108
let emphasisManager = target? . emphasisManager else { return }
94
109
95
110
// Check if there are any matches
96
111
if findMatches. isEmpty {
112
+ NSSound . beep ( )
113
+ BezelNotification . show (
114
+ symbolName: " arrow.up.to.line " ,
115
+ over: textViewController. textView
116
+ )
97
117
return
98
118
}
99
119
100
- // Update to previous match
101
- let oldIndex = currentFindMatchIndex
102
- currentFindMatchIndex = ( currentFindMatchIndex - 1 + findMatches. count) % findMatches. count
103
-
104
- // Show bezel notification if we cycled from first to last match
105
- if oldIndex == 0 && currentFindMatchIndex == findMatches. count - 1 {
120
+ // Check if we're at the first match and wrapAround is false
121
+ if !wrapAround && currentFindMatchIndex == 0 {
122
+ NSSound . beep ( )
106
123
BezelNotification . show (
107
- symbolName: " arrow.trianglehead.bottomleft.capsulepath.clockwise " ,
124
+ symbolName: " arrow.up.to.line " ,
108
125
over: textViewController. textView
109
126
)
127
+ if textViewController. textView. window? . firstResponder === textViewController. textView {
128
+ flashCurrentMatch ( emphasisManager: emphasisManager, textViewController: textViewController)
129
+ return
130
+ }
131
+ updateEmphasesForCurrentMatch ( emphasisManager: emphasisManager)
132
+ return
110
133
}
111
134
135
+ // Update to previous match∂
136
+ currentFindMatchIndex = ( currentFindMatchIndex - 1 + findMatches. count) % findMatches. count
137
+
112
138
// If the text view has focus, show a flash animation for the current match
113
139
if textViewController. textView. window? . firstResponder === textViewController. textView {
114
- let newActiveRange = findMatches [ currentFindMatchIndex]
115
-
116
- // Clear existing emphases before adding the flash
117
- emphasisManager. removeEmphases ( for: EmphasisGroup . find)
118
-
119
- emphasisManager. addEmphasis (
120
- Emphasis (
121
- range: newActiveRange,
122
- style: . standard,
123
- flash: true ,
124
- inactive: false ,
125
- selectInDocument: true
126
- ) ,
127
- for: EmphasisGroup . find
128
- )
129
-
140
+ flashCurrentMatch ( emphasisManager: emphasisManager, textViewController: textViewController)
130
141
return
131
142
}
132
143
133
- // Create updated emphases with new active state
144
+ updateEmphasesForCurrentMatch ( emphasisManager: emphasisManager)
145
+ }
146
+
147
+ private func updateEmphasesForCurrentMatch( emphasisManager: EmphasisManager , flash: Bool = false ) {
148
+ // Create updated emphases with current match emphasized
134
149
let updatedEmphases = findMatches. enumerated ( ) . map { index, range in
135
150
Emphasis (
136
151
range: range,
137
152
style: . standard,
138
- flash: false ,
153
+ flash: flash ,
139
154
inactive: index != currentFindMatchIndex,
140
155
selectInDocument: index == currentFindMatchIndex
141
156
)
@@ -151,7 +166,6 @@ extension FindViewController: FindPanelDelegate {
151
166
152
167
// Check if there are any matches
153
168
if findMatches. isEmpty {
154
- // Show "no matches" bezel notification and play beep
155
169
NSSound . beep ( )
156
170
BezelNotification . show (
157
171
symbolName: " arrow.down.to.line " ,
@@ -160,52 +174,31 @@ extension FindViewController: FindPanelDelegate {
160
174
return
161
175
}
162
176
163
- // Update to next match
164
- let oldIndex = currentFindMatchIndex
165
- currentFindMatchIndex = ( currentFindMatchIndex + 1 ) % findMatches. count
166
-
167
- // Show bezel notification if we cycled from last to first match
168
- if oldIndex == findMatches. count - 1 && currentFindMatchIndex == 0 {
177
+ // Check if we're at the last match and wrapAround is false
178
+ if !wrapAround && currentFindMatchIndex == findMatches. count - 1 {
179
+ NSSound . beep ( )
169
180
BezelNotification . show (
170
- symbolName: " arrow.triangle.capsulepath " ,
181
+ symbolName: " arrow.down.to.line " ,
171
182
over: textViewController. textView
172
183
)
184
+ if textViewController. textView. window? . firstResponder === textViewController. textView {
185
+ flashCurrentMatch ( emphasisManager: emphasisManager, textViewController: textViewController)
186
+ return
187
+ }
188
+ updateEmphasesForCurrentMatch ( emphasisManager: emphasisManager)
189
+ return
173
190
}
174
191
192
+ // Update to next match
193
+ currentFindMatchIndex = ( currentFindMatchIndex + 1 ) % findMatches. count
194
+
175
195
// If the text view has focus, show a flash animation for the current match
176
196
if textViewController. textView. window? . firstResponder === textViewController. textView {
177
- let newActiveRange = findMatches [ currentFindMatchIndex]
178
-
179
- // Clear existing emphases before adding the flash
180
- emphasisManager. removeEmphases ( for: EmphasisGroup . find)
181
-
182
- emphasisManager. addEmphasis (
183
- Emphasis (
184
- range: newActiveRange,
185
- style: . standard,
186
- flash: true ,
187
- inactive: false ,
188
- selectInDocument: true
189
- ) ,
190
- for: EmphasisGroup . find
191
- )
192
-
197
+ flashCurrentMatch ( emphasisManager: emphasisManager, textViewController: textViewController)
193
198
return
194
199
}
195
200
196
- // Create updated emphases with new active state
197
- let updatedEmphases = findMatches. enumerated ( ) . map { index, range in
198
- Emphasis (
199
- range: range,
200
- style: . standard,
201
- flash: false ,
202
- inactive: index != currentFindMatchIndex,
203
- selectInDocument: index == currentFindMatchIndex
204
- )
205
- }
206
-
207
- // Replace all emphases to update state
208
- emphasisManager. replaceEmphases ( updatedEmphases, for: EmphasisGroup . find)
201
+ updateEmphasesForCurrentMatch ( emphasisManager: emphasisManager)
209
202
}
210
203
211
204
func findPanelUpdateMatchCount( _ count: Int ) {
0 commit comments