Skip to content

Commit 1e18e26

Browse files
authored
Merge pull request #860 from Garulf/Fix-misaligned-suggestion-text
Fix misaligned suggestion text
2 parents 06a76f5 + 3282f85 commit 1e18e26

File tree

3 files changed

+17
-6
lines changed

3 files changed

+17
-6
lines changed

Flow.Launcher/Converters/QuerySuggestionBoxConverter.cs

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
using System;
22
using System.Globalization;
3+
using System.Windows.Controls;
34
using System.Windows.Data;
5+
using System.Windows.Media;
46
using Flow.Launcher.Infrastructure.Logger;
57
using 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)

Flow.Launcher/MainWindow.xaml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -163,8 +163,9 @@
163163
Style="{DynamicResource QuerySuggestionBoxStyle}">
164164
<TextBox.Text>
165165
<MultiBinding Converter="{StaticResource QuerySuggestionBoxConverter}">
166-
<Binding ElementName="QueryTextBox" Path="Text" />
166+
<Binding ElementName="QueryTextBox" Mode="OneTime" />
167167
<Binding ElementName="ResultListBox" Path="SelectedItem" />
168+
<Binding ElementName="QueryTextBox" Path="Text" />
168169
</MultiBinding>
169170
</TextBox.Text>
170171
</TextBox>

Flow.Launcher/MainWindow.xaml.cs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -274,7 +274,6 @@ private void InitProgressbarAnimation()
274274
_viewModel.ProgressBarVisibility = Visibility.Hidden;
275275
isProgressBarStoryboardPaused = true;
276276
}
277-
278277
public void WindowAnimator()
279278
{
280279
if (_animating)

0 commit comments

Comments
 (0)