11using System ;
22using System . Globalization ;
3+ using System . Windows . Controls ;
34using System . Windows . Data ;
5+ using System . Windows . Media ;
46using Flow . Launcher . Infrastructure . Logger ;
57using Flow . Launcher . ViewModel ;
68
@@ -10,13 +12,13 @@ public class QuerySuggestionBoxConverter : IMultiValueConverter
1012 {
1113 public object Convert ( object [ ] values , Type targetType , object parameter , CultureInfo culture )
1214 {
13- if ( values . Length != 2 )
15+ if ( values . Length != 3 )
1416 {
1517 return string . Empty ;
1618 }
19+ var QueryTextBox = values [ 0 ] as TextBox ;
1720
18- // first prop is the current query string
19- var queryText = ( string ) values [ 0 ] ;
21+ var queryText = ( string ) values [ 2 ] ;
2022
2123 if ( string . IsNullOrEmpty ( queryText ) )
2224 return string . Empty ;
@@ -43,10 +45,19 @@ public object Convert(object[] values, Type targetType, object parameter, Cultur
4345 if ( ! selectedResultPossibleSuggestion . StartsWith ( queryText , StringComparison . CurrentCultureIgnoreCase ) )
4446 return string . Empty ;
4547
48+
4649 // For AutocompleteQueryCommand.
4750 // When user typed lower case and result title is uppercase, we still want to display suggestion
4851 selectedItem . QuerySuggestionText = queryText + selectedResultPossibleSuggestion . Substring ( queryText . Length ) ;
49-
52+
53+ // Check if Text will be larger then our QueryTextBox
54+ System . Windows . Media . Typeface typeface = new Typeface ( QueryTextBox . FontFamily , QueryTextBox . FontStyle , QueryTextBox . FontWeight , QueryTextBox . FontStretch ) ;
55+ System . Windows . Media . FormattedText ft = new FormattedText ( QueryTextBox . Text , System . Globalization . CultureInfo . CurrentCulture , System . Windows . FlowDirection . LeftToRight , typeface , QueryTextBox . FontSize , Brushes . Black ) ;
56+ if ( ft . Width > QueryTextBox . ActualWidth || QueryTextBox . HorizontalOffset != 0 )
57+ {
58+ return string . Empty ;
59+ } ;
60+
5061 return selectedItem . QuerySuggestionText ;
5162 }
5263 catch ( Exception e )
0 commit comments