@@ -12,7 +12,8 @@ import CodeEditSymbols
1212struct FindPanelView : View {
1313 @Environment ( \. controlActiveState) var activeState
1414 @ObservedObject var viewModel : FindPanelViewModel
15- @FocusState private var isFocused : Bool
15+ @FocusState private var isFindFieldFocused : Bool
16+ @FocusState private var isReplaceFieldFocused : Bool
1617
1718 var body : some View {
1819 VStack ( spacing: 5 ) {
@@ -24,7 +25,13 @@ struct FindPanelView: View {
2425 FindModePicker (
2526 mode: $viewModel. mode,
2627 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+ }
2835 )
2936 . background ( GeometryReader { geometry in
3037 Color . clear. onAppear {
@@ -60,9 +67,9 @@ struct FindPanelView: View {
6067 clearable: true
6168 )
6269 . 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 )
6673 }
6774 . onSubmit {
6875 viewModel. onSubmit ( )
@@ -120,7 +127,10 @@ struct FindPanelView: View {
120127 clearable: true
121128 )
122129 . 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+ }
124134 HStack ( spacing: 4 ) {
125135 ControlGroup {
126136 Button ( action: {
@@ -168,12 +178,11 @@ struct FindPanelView: View {
168178 viewModel. onMatchCaseChange ( newValue)
169179 }
170180 . onChange ( of: viewModel. isFocused) { newValue in
171- isFocused = newValue
181+ isFindFieldFocused = newValue
172182 if !newValue {
173183 viewModel. removeEmphasis ( )
174184 }
175185 }
176-
177186 }
178187}
179188
0 commit comments