Skip to content

Commit 1dd9e2c

Browse files
committed
Calculate if text font is larger then area
1 parent 8892ad2 commit 1dd9e2c

File tree

1 file changed

+11
-2
lines changed

1 file changed

+11
-2
lines changed

Flow.Launcher/Converters/QuerySuggestionBoxConverter.cs

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
using System.Globalization;
33
using System.Windows.Controls;
44
using System.Windows.Data;
5+
using System.Windows.Media;
56
using Flow.Launcher.Infrastructure.Logger;
67
using Flow.Launcher.ViewModel;
78

@@ -41,13 +42,21 @@ public object Convert(object[] values, Type targetType, object parameter, Cultur
4142
var selectedResultActionKeyword = string.IsNullOrEmpty(selectedResult.ActionKeywordAssigned) ? "" : selectedResult.ActionKeywordAssigned + " ";
4243
var selectedResultPossibleSuggestion = selectedResultActionKeyword + selectedResult.Title;
4344

44-
if (!selectedResultPossibleSuggestion.StartsWith(queryText, StringComparison.CurrentCultureIgnoreCase) || QueryTextBox.HorizontalOffset != 0)
45+
if (!selectedResultPossibleSuggestion.StartsWith(queryText, StringComparison.CurrentCultureIgnoreCase))
4546
return string.Empty;
4647

48+
4749
// For AutocompleteQueryCommand.
4850
// When user typed lower case and result title is uppercase, we still want to display suggestion
4951
selectedItem.QuerySuggestionText = queryText + selectedResultPossibleSuggestion.Substring(queryText.Length);
50-
52+
53+
System.Windows.Media.Typeface typeface = new Typeface(QueryTextBox.FontFamily, QueryTextBox.FontStyle, QueryTextBox.FontWeight, QueryTextBox.FontStretch);
54+
System.Windows.Media.FormattedText ft = new FormattedText(QueryTextBox.Text, System.Globalization.CultureInfo.CurrentCulture, System.Windows.FlowDirection.LeftToRight, typeface, QueryTextBox.FontSize, Brushes.Black);
55+
if (ft.Width > QueryTextBox.ActualWidth)
56+
{
57+
return string.Empty;
58+
};
59+
5160
return selectedItem.QuerySuggestionText;
5261
}
5362
catch (Exception e)

0 commit comments

Comments
 (0)