@@ -16,7 +16,7 @@ import SwiftUI
1616/// It is generic on its view model protocol, allowing tests to inject mock view models.
1717struct ConfigVariableDetailView < ViewModel: ConfigVariableDetailViewModeling > : View {
1818 @State var viewModel : ViewModel
19- @FocusState private var isTextEditorFocused : Bool
19+ @FocusState private var isEditorControlFocused : Bool
2020
2121
2222 var body : some View {
@@ -26,7 +26,24 @@ struct ConfigVariableDetailView<ViewModel: ConfigVariableDetailViewModeling>: Vi
2626 providerValuesSection
2727 metadataSection
2828 }
29+ . onDisappear {
30+ if isEditorControlFocused && viewModel. isOverrideTextValid {
31+ viewModel. commitOverrideText ( )
32+ }
33+ }
2934 . navigationTitle ( viewModel. displayName)
35+ . toolbar {
36+ ToolbarItemGroup ( placement: . keyboard) {
37+ if isEditorControlFocused {
38+ Spacer ( )
39+ Button ( role: . confirm) {
40+ viewModel. commitOverrideText ( )
41+ isEditorControlFocused = false
42+ }
43+ . disabled ( !viewModel. isOverrideTextValid)
44+ }
45+ }
46+ }
3047 }
3148}
3249
@@ -120,30 +137,21 @@ extension ConfigVariableDetailView {
120137 VStack ( alignment: . leading) {
121138 Text ( localizedStringResource ( " detailView.overrideSection.valueLabel " ) )
122139 TextEditor ( text: $viewModel. overrideText)
123- . focused ( $isTextEditorFocused )
140+ . focused ( $isEditorControlFocused )
124141 . font ( . caption. monospaced ( ) )
125142 . frame ( minHeight: 100 )
126143 . border ( viewModel. isOverrideTextValid ? Color . clear : Color . red)
127144 . autocorrectionDisabled ( )
128145 . textInputAutocapitalization ( . never)
129146 . keyboardType ( . asciiCapable)
130-
131- HStack {
132- Spacer ( )
133- Button ( localizedStringResource ( " detailView.overrideSection.applyButton " ) ) {
134- viewModel. commitOverrideText ( )
135- isTextEditorFocused = false
136- }
137- . buttonStyle ( . bordered)
138- . disabled ( !viewModel. isOverrideTextValid)
139- }
140147 }
141148 case . textField, . numberField, . decimalField:
142149 LabeledContent ( localizedStringResource ( " detailView.overrideSection.valueLabel " ) ) {
143150 TextField (
144151 localizedStringResource ( " detailView.overrideSection.valueTextField " ) ,
145152 text: $viewModel. overrideText,
146153 )
154+ . focused ( $isEditorControlFocused)
147155 . onSubmit { viewModel. commitOverrideText ( ) }
148156 . textFieldStyle ( . plain)
149157 . multilineTextAlignment ( . trailing)
0 commit comments