@@ -12,7 +12,8 @@ import CodeEditSymbols
12
12
struct FindPanelView : View {
13
13
@Environment ( \. controlActiveState) var activeState
14
14
@ObservedObject var viewModel : FindPanelViewModel
15
- @FocusState private var isFocused : Bool
15
+ @FocusState private var isFindFieldFocused : Bool
16
+ @FocusState private var isReplaceFieldFocused : Bool
16
17
17
18
var body : some View {
18
19
VStack ( spacing: 5 ) {
@@ -24,7 +25,13 @@ struct FindPanelView: View {
24
25
FindModePicker (
25
26
mode: $viewModel. mode,
26
27
wrapAround: $viewModel. wrapAround,
27
- onToggleWrapAround: viewModel. toggleWrapAround
28
+ onToggleWrapAround: viewModel. toggleWrapAround,
29
+ onModeChange: {
30
+ isFindFieldFocused = true
31
+ if let textField = NSApp . keyWindow? . firstResponder as? NSTextView {
32
+ textField. selectAll ( nil )
33
+ }
34
+ }
28
35
)
29
36
. background ( GeometryReader { geometry in
30
37
Color . clear. onAppear {
@@ -60,9 +67,9 @@ struct FindPanelView: View {
60
67
clearable: true
61
68
)
62
69
. controlSize ( . small)
63
- . focused ( $isFocused )
64
- . onChange ( of: isFocused ) { newValue in
65
- viewModel. setFocus ( newValue)
70
+ . focused ( $isFindFieldFocused )
71
+ . onChange ( of: isFindFieldFocused ) { newValue in
72
+ viewModel. setFocus ( newValue || isReplaceFieldFocused )
66
73
}
67
74
. onSubmit {
68
75
viewModel. onSubmit ( )
@@ -120,7 +127,10 @@ struct FindPanelView: View {
120
127
clearable: true
121
128
)
122
129
. controlSize ( . small)
123
- // TODO: Handle replace text field focus and submit
130
+ . focused ( $isReplaceFieldFocused)
131
+ . onChange ( of: isReplaceFieldFocused) { newValue in
132
+ viewModel. setFocus ( newValue || isFindFieldFocused)
133
+ }
124
134
HStack ( spacing: 4 ) {
125
135
ControlGroup {
126
136
Button ( action: {
@@ -168,12 +178,11 @@ struct FindPanelView: View {
168
178
viewModel. onMatchCaseChange ( newValue)
169
179
}
170
180
. onChange ( of: viewModel. isFocused) { newValue in
171
- isFocused = newValue
181
+ isFindFieldFocused = newValue
172
182
if !newValue {
173
183
viewModel. removeEmphasis ( )
174
184
}
175
185
}
176
-
177
186
}
178
187
}
179
188
0 commit comments