@@ -28,7 +28,6 @@ public partial class Omnibar : Control
28
28
private Border _textBoxSuggestionsContainerBorder = null ! ;
29
29
private ListView _textBoxSuggestionsListView = null ! ;
30
30
31
- private bool _isFocused ;
32
31
private string _userInput = string . Empty ;
33
32
private OmnibarTextChangeReason _textChangeReason = OmnibarTextChangeReason . None ;
34
33
@@ -148,15 +147,15 @@ public void ChangeMode(OmnibarMode modeToExpand, bool shouldFocus = false, bool
148
147
CurrentSelectedMode = modeToExpand ;
149
148
150
149
_textChangeReason = OmnibarTextChangeReason . ProgrammaticChange ;
151
- _textBox . Text = CurrentSelectedMode . Text ?? string . Empty ;
150
+ ChangeTextBoxText ( CurrentSelectedMode . Text ?? string . Empty ) ;
152
151
153
152
// Move cursor of the TextBox to the tail
154
153
_textBox . Select ( _textBox . Text . Length , 0 ) ;
155
154
156
155
VisualStateManager . GoToState ( CurrentSelectedMode , "Focused" , true ) ;
157
156
CurrentSelectedMode . OnChangingCurrentMode ( true ) ;
158
157
159
- if ( _isFocused )
158
+ if ( IsFocused )
160
159
{
161
160
VisualStateManager . GoToState ( CurrentSelectedMode , "Focused" , true ) ;
162
161
VisualStateManager . GoToState ( _textBox , "InputAreaVisible" , true ) ;
@@ -174,7 +173,7 @@ public void ChangeMode(OmnibarMode modeToExpand, bool shouldFocus = false, bool
174
173
if ( shouldFocus )
175
174
_textBox . Focus ( FocusState . Keyboard ) ;
176
175
177
- TryToggleIsSuggestionsPopupOpen ( _isFocused && CurrentSelectedMode ? . SuggestionItemsSource is not null ) ;
176
+ TryToggleIsSuggestionsPopupOpen ( IsFocused && CurrentSelectedMode ? . SuggestionItemsSource is not null ) ;
178
177
179
178
// Remove the reposition transition from the all modes
180
179
if ( useTransition )
@@ -189,7 +188,7 @@ public void ChangeMode(OmnibarMode modeToExpand, bool shouldFocus = false, bool
189
188
190
189
public bool TryToggleIsSuggestionsPopupOpen ( bool wantToOpen )
191
190
{
192
- if ( wantToOpen && ( ! _isFocused || CurrentSelectedMode ? . SuggestionItemsSource is null ) )
191
+ if ( wantToOpen && ( ! IsFocused || CurrentSelectedMode ? . SuggestionItemsSource is null || ( CurrentSelectedMode ? . SuggestionItemsSource is IList collection && collection . Count is 0 ) ) )
193
192
return false ;
194
193
195
194
_textBoxSuggestionsPopup . IsOpen = wantToOpen ;
@@ -205,10 +204,15 @@ public void ChooseSuggestionItem(object obj)
205
204
if ( CurrentSelectedMode . UpdateTextOnSelect )
206
205
{
207
206
_textChangeReason = OmnibarTextChangeReason . SuggestionChosen ;
208
- _textBox . Text = GetObjectText ( obj ) ;
207
+ ChangeTextBoxText ( GetObjectText ( obj ) ) ;
209
208
}
210
209
211
210
SuggestionChosen ? . Invoke ( this , new ( CurrentSelectedMode , obj ) ) ;
211
+ }
212
+
213
+ internal protected void ChangeTextBoxText ( string text )
214
+ {
215
+ _textBox . Text = text ;
212
216
213
217
// Move the cursor to the end of the TextBox
214
218
_textBox ? . Select ( _textBox . Text . Length , 0 ) ;
@@ -233,7 +237,7 @@ private string GetObjectText(object obj)
233
237
return obj is string text
234
238
? text
235
239
: obj is IOmnibarTextMemberPathProvider textMemberPathProvider
236
- ? textMemberPathProvider . GetTextMemberPath ( CurrentSelectedMode . DisplayMemberPath ?? string . Empty )
240
+ ? textMemberPathProvider . GetTextMemberPath ( CurrentSelectedMode . TextMemberPath ?? string . Empty )
237
241
: obj . ToString ( ) ?? string . Empty ;
238
242
}
239
243
@@ -245,10 +249,7 @@ private void RevertTextToUserInput()
245
249
_textBoxSuggestionsListView . SelectedIndex = - 1 ;
246
250
_textChangeReason = OmnibarTextChangeReason . ProgrammaticChange ;
247
251
248
- _textBox . Text = _userInput ?? "" ;
249
-
250
- // Move the cursor to the end of the TextBox
251
- _textBox ? . Select ( _textBox . Text . Length , 0 ) ;
252
+ ChangeTextBoxText ( _userInput ?? "" ) ;
252
253
}
253
254
}
254
255
}
0 commit comments