@@ -28,7 +28,6 @@ public partial class Omnibar : Control
2828 private Border _textBoxSuggestionsContainerBorder = null ! ;
2929 private ListView _textBoxSuggestionsListView = null ! ;
3030
31- private bool _isFocused ;
3231 private string _userInput = string . Empty ;
3332 private OmnibarTextChangeReason _textChangeReason = OmnibarTextChangeReason . None ;
3433
@@ -148,15 +147,15 @@ public void ChangeMode(OmnibarMode modeToExpand, bool shouldFocus = false, bool
148147 CurrentSelectedMode = modeToExpand ;
149148
150149 _textChangeReason = OmnibarTextChangeReason . ProgrammaticChange ;
151- _textBox . Text = CurrentSelectedMode . Text ?? string . Empty ;
150+ ChangeTextBoxText ( CurrentSelectedMode . Text ?? string . Empty ) ;
152151
153152 // Move cursor of the TextBox to the tail
154153 _textBox . Select ( _textBox . Text . Length , 0 ) ;
155154
156155 VisualStateManager . GoToState ( CurrentSelectedMode , "Focused" , true ) ;
157156 CurrentSelectedMode . OnChangingCurrentMode ( true ) ;
158157
159- if ( _isFocused )
158+ if ( IsFocused )
160159 {
161160 VisualStateManager . GoToState ( CurrentSelectedMode , "Focused" , true ) ;
162161 VisualStateManager . GoToState ( _textBox , "InputAreaVisible" , true ) ;
@@ -174,7 +173,7 @@ public void ChangeMode(OmnibarMode modeToExpand, bool shouldFocus = false, bool
174173 if ( shouldFocus )
175174 _textBox . Focus ( FocusState . Keyboard ) ;
176175
177- TryToggleIsSuggestionsPopupOpen ( _isFocused && CurrentSelectedMode ? . SuggestionItemsSource is not null ) ;
176+ TryToggleIsSuggestionsPopupOpen ( IsFocused && CurrentSelectedMode ? . SuggestionItemsSource is not null ) ;
178177
179178 // Remove the reposition transition from the all modes
180179 if ( useTransition )
@@ -189,7 +188,7 @@ public void ChangeMode(OmnibarMode modeToExpand, bool shouldFocus = false, bool
189188
190189 public bool TryToggleIsSuggestionsPopupOpen ( bool wantToOpen )
191190 {
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 ) ) )
193192 return false ;
194193
195194 _textBoxSuggestionsPopup . IsOpen = wantToOpen ;
@@ -205,10 +204,15 @@ public void ChooseSuggestionItem(object obj)
205204 if ( CurrentSelectedMode . UpdateTextOnSelect )
206205 {
207206 _textChangeReason = OmnibarTextChangeReason . SuggestionChosen ;
208- _textBox . Text = GetObjectText ( obj ) ;
207+ ChangeTextBoxText ( GetObjectText ( obj ) ) ;
209208 }
210209
211210 SuggestionChosen ? . Invoke ( this , new ( CurrentSelectedMode , obj ) ) ;
211+ }
212+
213+ internal protected void ChangeTextBoxText ( string text )
214+ {
215+ _textBox . Text = text ;
212216
213217 // Move the cursor to the end of the TextBox
214218 _textBox ? . Select ( _textBox . Text . Length , 0 ) ;
@@ -233,7 +237,7 @@ private string GetObjectText(object obj)
233237 return obj is string text
234238 ? text
235239 : obj is IOmnibarTextMemberPathProvider textMemberPathProvider
236- ? textMemberPathProvider . GetTextMemberPath ( CurrentSelectedMode . DisplayMemberPath ?? string . Empty )
240+ ? textMemberPathProvider . GetTextMemberPath ( CurrentSelectedMode . TextMemberPath ?? string . Empty )
237241 : obj . ToString ( ) ?? string . Empty ;
238242 }
239243
@@ -245,10 +249,7 @@ private void RevertTextToUserInput()
245249 _textBoxSuggestionsListView . SelectedIndex = - 1 ;
246250 _textChangeReason = OmnibarTextChangeReason . ProgrammaticChange ;
247251
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 ?? "" ) ;
252253 }
253254 }
254255}
0 commit comments