@@ -33,15 +33,39 @@ values[2] is not string queryText ||
3333 {
3434 var selectedResult = selectedItem . Result ;
3535 var selectedResultActionKeyword = string . IsNullOrEmpty ( selectedResult . ActionKeywordAssigned ) ? "" : selectedResult . ActionKeywordAssigned + " " ;
36- var selectedResultPossibleSuggestion = selectedResultActionKeyword + selectedResult . Title ;
3736
38- if ( ! selectedResultPossibleSuggestion . StartsWith ( queryText , StringComparison . CurrentCultureIgnoreCase ) )
39- return string . Empty ;
37+ string selectedResultPossibleSuggestion = null ;
38+
39+ // Firstly check if the result has QuerySuggestionText
40+ if ( ! string . IsNullOrEmpty ( selectedResult . QuerySuggestionText ) )
41+ {
42+ selectedResultPossibleSuggestion = selectedResultActionKeyword + selectedResult . QuerySuggestionText ;
43+
44+ // If this QuerySuggestionText does not start with the queryText, set it to null
45+ if ( ! selectedResultPossibleSuggestion . StartsWith ( queryText , StringComparison . CurrentCultureIgnoreCase ) )
46+ {
47+ selectedResultPossibleSuggestion = null ;
48+ }
49+ }
50+
51+ // Then check Title as suggestion
52+ if ( string . IsNullOrEmpty ( selectedResultPossibleSuggestion ) )
53+ {
54+ selectedResultPossibleSuggestion = selectedResultActionKeyword + selectedResult . Title ;
4055
56+ // If this QuerySuggestionText does not start with the queryText, set it to null
57+ if ( ! selectedResultPossibleSuggestion . StartsWith ( queryText , StringComparison . CurrentCultureIgnoreCase ) )
58+ {
59+ selectedResultPossibleSuggestion = null ;
60+ }
61+ }
62+
63+ if ( string . IsNullOrEmpty ( selectedResultPossibleSuggestion ) )
64+ return string . Empty ;
4165
4266 // For AutocompleteQueryCommand.
4367 // When user typed lower case and result title is uppercase, we still want to display suggestion
44- selectedItem . QuerySuggestionText = queryText + selectedResultPossibleSuggestion . Substring ( queryText . Length ) ;
68+ selectedItem . QuerySuggestionText = string . Concat ( queryText , selectedResultPossibleSuggestion . AsSpan ( queryText . Length ) ) ;
4569
4670 // Check if Text will be larger than our QueryTextBox
4771 Typeface typeface = new Typeface ( queryTextBox . FontFamily , queryTextBox . FontStyle , queryTextBox . FontWeight , queryTextBox . FontStretch ) ;
0 commit comments