Skip to content

Commit

Permalink
Merge pull request #860 from Garulf/Fix-misaligned-suggestion-text
Browse files Browse the repository at this point in the history
Fix misaligned suggestion text
  • Loading branch information
Garulf authored Dec 5, 2021
2 parents 06a76f5 + 3282f85 commit 1e18e26
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 6 deletions.
19 changes: 15 additions & 4 deletions Flow.Launcher/Converters/QuerySuggestionBoxConverter.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
using System;
using System.Globalization;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Media;
using Flow.Launcher.Infrastructure.Logger;
using Flow.Launcher.ViewModel;

Expand All @@ -10,13 +12,13 @@ public class QuerySuggestionBoxConverter : IMultiValueConverter
{
public object Convert(object[] values, Type targetType, object parameter, CultureInfo culture)
{
if (values.Length != 2)
if (values.Length != 3)
{
return string.Empty;
}
var QueryTextBox = values[0] as TextBox;

// first prop is the current query string
var queryText = (string)values[0];
var queryText = (string)values[2];

if (string.IsNullOrEmpty(queryText))
return string.Empty;
Expand All @@ -43,10 +45,19 @@ public object Convert(object[] values, Type targetType, object parameter, Cultur
if (!selectedResultPossibleSuggestion.StartsWith(queryText, StringComparison.CurrentCultureIgnoreCase))
return string.Empty;


// For AutocompleteQueryCommand.
// When user typed lower case and result title is uppercase, we still want to display suggestion
selectedItem.QuerySuggestionText = queryText + selectedResultPossibleSuggestion.Substring(queryText.Length);


// Check if Text will be larger then our QueryTextBox
System.Windows.Media.Typeface typeface = new Typeface(QueryTextBox.FontFamily, QueryTextBox.FontStyle, QueryTextBox.FontWeight, QueryTextBox.FontStretch);
System.Windows.Media.FormattedText ft = new FormattedText(QueryTextBox.Text, System.Globalization.CultureInfo.CurrentCulture, System.Windows.FlowDirection.LeftToRight, typeface, QueryTextBox.FontSize, Brushes.Black);
if (ft.Width > QueryTextBox.ActualWidth || QueryTextBox.HorizontalOffset != 0)
{
return string.Empty;
};

return selectedItem.QuerySuggestionText;
}
catch (Exception e)
Expand Down
3 changes: 2 additions & 1 deletion Flow.Launcher/MainWindow.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -163,8 +163,9 @@
Style="{DynamicResource QuerySuggestionBoxStyle}">
<TextBox.Text>
<MultiBinding Converter="{StaticResource QuerySuggestionBoxConverter}">
<Binding ElementName="QueryTextBox" Path="Text" />
<Binding ElementName="QueryTextBox" Mode="OneTime" />
<Binding ElementName="ResultListBox" Path="SelectedItem" />
<Binding ElementName="QueryTextBox" Path="Text" />
</MultiBinding>
</TextBox.Text>
</TextBox>
Expand Down
1 change: 0 additions & 1 deletion Flow.Launcher/MainWindow.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -274,7 +274,6 @@ private void InitProgressbarAnimation()
_viewModel.ProgressBarVisibility = Visibility.Hidden;
isProgressBarStoryboardPaused = true;
}

public void WindowAnimator()
{
if (_animating)
Expand Down

0 comments on commit 1e18e26

Please sign in to comment.