From 09e10c4ce84fdd470801386d437f26feae10373b Mon Sep 17 00:00:00 2001 From: Garulf <535299+Garulf@users.noreply.github.com> Date: Sat, 4 Dec 2021 02:04:57 -0500 Subject: [PATCH 01/12] Initial commit --- Flow.Launcher/MainWindow.xaml | 1 + Flow.Launcher/MainWindow.xaml.cs | 8 ++++++++ 2 files changed, 9 insertions(+) diff --git a/Flow.Launcher/MainWindow.xaml b/Flow.Launcher/MainWindow.xaml index dd897965075..618cee60983 100644 --- a/Flow.Launcher/MainWindow.xaml +++ b/Flow.Launcher/MainWindow.xaml @@ -172,6 +172,7 @@ Background="Transparent" PreviewDragOver="OnPreviewDragOver" Style="{DynamicResource QueryBoxStyle}" + SelectionChanged="TextBox_SelectionChanged" Text="{Binding QueryText, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}" Visibility="Visible"> diff --git a/Flow.Launcher/MainWindow.xaml.cs b/Flow.Launcher/MainWindow.xaml.cs index ba0b63a5211..749f006c721 100644 --- a/Flow.Launcher/MainWindow.xaml.cs +++ b/Flow.Launcher/MainWindow.xaml.cs @@ -260,6 +260,14 @@ private void InitProgressbarAnimation() isProgressBarStoryboardPaused = true; } + private void TextBox_SelectionChanged(object sender, RoutedEventArgs e) + { + + // QueryTextSuggestionBox.ScrollToCaret(); + QueryTextSuggestionBox.ScrollToLine(QueryTextBox.GetLineIndexFromCharacterIndex(QueryTextBox.SelectionStart)); + QueryTextSuggestionBox.CaretIndex = QueryTextBox.CaretIndex; + } + public void WindowAnimator() { if (_animating) From 846333af1ef868c3f7f497d467ddd1b18dab2b16 Mon Sep 17 00:00:00 2001 From: Garulf <535299+Garulf@users.noreply.github.com> Date: Sat, 4 Dec 2021 03:51:21 -0500 Subject: [PATCH 02/12] Initial commit --- .../Converters/QuerySuggestionBoxConverter.cs | 11 +++++++---- Flow.Launcher/MainWindow.xaml | 8 ++++---- Flow.Launcher/MainWindow.xaml.cs | 6 ++++-- 3 files changed, 15 insertions(+), 10 deletions(-) diff --git a/Flow.Launcher/Converters/QuerySuggestionBoxConverter.cs b/Flow.Launcher/Converters/QuerySuggestionBoxConverter.cs index c70796a6d4e..3de95fe479f 100644 --- a/Flow.Launcher/Converters/QuerySuggestionBoxConverter.cs +++ b/Flow.Launcher/Converters/QuerySuggestionBoxConverter.cs @@ -1,5 +1,6 @@ using System; using System.Globalization; +using System.Windows.Controls; using System.Windows.Data; using Flow.Launcher.Infrastructure.Logger; using Flow.Launcher.ViewModel; @@ -10,19 +11,21 @@ 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 QueryText = values[1] as TextBox; + var Suggestion = values[0] as TextBox; + Suggestion.ScrollToHorizontalOffset(QueryText.HorizontalOffset); // first prop is the current query string - var queryText = (string)values[0]; + var queryText = QueryText.Text; if (string.IsNullOrEmpty(queryText)) return string.Empty; // second prop is the current selected item result - var val = values[1]; + var val = values[2]; if (val == null) { return string.Empty; diff --git a/Flow.Launcher/MainWindow.xaml b/Flow.Launcher/MainWindow.xaml index 618cee60983..b419c20920b 100644 --- a/Flow.Launcher/MainWindow.xaml +++ b/Flow.Launcher/MainWindow.xaml @@ -161,7 +161,8 @@ Style="{DynamicResource QuerySuggestionBoxStyle}"> - + + @@ -171,10 +172,9 @@ AllowDrop="True" Background="Transparent" PreviewDragOver="OnPreviewDragOver" - Style="{DynamicResource QueryBoxStyle}" - SelectionChanged="TextBox_SelectionChanged" + Style="{DynamicResource QueryBoxStyle }" Text="{Binding QueryText, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}" - Visibility="Visible"> + Visibility="Visible" Margin="16,7,0,7"> diff --git a/Flow.Launcher/MainWindow.xaml.cs b/Flow.Launcher/MainWindow.xaml.cs index 749f006c721..e2c443b1216 100644 --- a/Flow.Launcher/MainWindow.xaml.cs +++ b/Flow.Launcher/MainWindow.xaml.cs @@ -262,10 +262,12 @@ private void InitProgressbarAnimation() private void TextBox_SelectionChanged(object sender, RoutedEventArgs e) { - + // QueryTextSuggestionBox.ScrollToCaret(); - QueryTextSuggestionBox.ScrollToLine(QueryTextBox.GetLineIndexFromCharacterIndex(QueryTextBox.SelectionStart)); QueryTextSuggestionBox.CaretIndex = QueryTextBox.CaretIndex; + QueryTextSuggestionBox.ScrollToHorizontalOffset(QueryTextBox.HorizontalOffset); + + } public void WindowAnimator() From ab2fe8fdc3f28efcb04c111506c9edcb4d6cbfeb Mon Sep 17 00:00:00 2001 From: Garulf <535299+Garulf@users.noreply.github.com> Date: Sat, 4 Dec 2021 04:03:26 -0500 Subject: [PATCH 03/12] Move suggestion caret --- Flow.Launcher/Converters/QuerySuggestionBoxConverter.cs | 2 ++ 1 file changed, 2 insertions(+) diff --git a/Flow.Launcher/Converters/QuerySuggestionBoxConverter.cs b/Flow.Launcher/Converters/QuerySuggestionBoxConverter.cs index 3de95fe479f..64e75f5730a 100644 --- a/Flow.Launcher/Converters/QuerySuggestionBoxConverter.cs +++ b/Flow.Launcher/Converters/QuerySuggestionBoxConverter.cs @@ -17,7 +17,9 @@ public object Convert(object[] values, Type targetType, object parameter, Cultur } var QueryText = values[1] as TextBox; var Suggestion = values[0] as TextBox; + Suggestion.CaretIndex = QueryText.CaretIndex; Suggestion.ScrollToHorizontalOffset(QueryText.HorizontalOffset); + // first prop is the current query string var queryText = QueryText.Text; From e9102f31932ecb076ca7d11ff1b12f4d73658dfc Mon Sep 17 00:00:00 2001 From: Garulf <535299+Garulf@users.noreply.github.com> Date: Sat, 4 Dec 2021 04:03:38 -0500 Subject: [PATCH 04/12] Revert accidental change --- Flow.Launcher/MainWindow.xaml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Flow.Launcher/MainWindow.xaml b/Flow.Launcher/MainWindow.xaml index b419c20920b..66278905ffd 100644 --- a/Flow.Launcher/MainWindow.xaml +++ b/Flow.Launcher/MainWindow.xaml @@ -172,9 +172,9 @@ AllowDrop="True" Background="Transparent" PreviewDragOver="OnPreviewDragOver" - Style="{DynamicResource QueryBoxStyle }" + Style="{DynamicResource QueryBoxStyle}" Text="{Binding QueryText, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}" - Visibility="Visible" Margin="16,7,0,7"> + Visibility="Visible"> From 984f2a137fbf593b3a77ed592d03d112bb918da6 Mon Sep 17 00:00:00 2001 From: Garulf <535299+Garulf@users.noreply.github.com> Date: Sat, 4 Dec 2021 04:04:55 -0500 Subject: [PATCH 05/12] Remove unused function --- Flow.Launcher/MainWindow.xaml.cs | 11 ----------- 1 file changed, 11 deletions(-) diff --git a/Flow.Launcher/MainWindow.xaml.cs b/Flow.Launcher/MainWindow.xaml.cs index e2c443b1216..7ab4371c9f4 100644 --- a/Flow.Launcher/MainWindow.xaml.cs +++ b/Flow.Launcher/MainWindow.xaml.cs @@ -259,17 +259,6 @@ private void InitProgressbarAnimation() _viewModel.ProgressBarVisibility = Visibility.Hidden; isProgressBarStoryboardPaused = true; } - - private void TextBox_SelectionChanged(object sender, RoutedEventArgs e) - { - - // QueryTextSuggestionBox.ScrollToCaret(); - QueryTextSuggestionBox.CaretIndex = QueryTextBox.CaretIndex; - QueryTextSuggestionBox.ScrollToHorizontalOffset(QueryTextBox.HorizontalOffset); - - - } - public void WindowAnimator() { if (_animating) From 64b3a62dd989838c2008938c7cec8fd3f0e7f953 Mon Sep 17 00:00:00 2001 From: Garulf <535299+Garulf@users.noreply.github.com> Date: Sat, 4 Dec 2021 13:31:54 -0500 Subject: [PATCH 06/12] When QueryTextBox scrolls hide Suggestion --- .../Converters/QuerySuggestionBoxConverter.cs | 12 +++++------- Flow.Launcher/MainWindow.xaml | 1 - 2 files changed, 5 insertions(+), 8 deletions(-) diff --git a/Flow.Launcher/Converters/QuerySuggestionBoxConverter.cs b/Flow.Launcher/Converters/QuerySuggestionBoxConverter.cs index 64e75f5730a..bfff2782934 100644 --- a/Flow.Launcher/Converters/QuerySuggestionBoxConverter.cs +++ b/Flow.Launcher/Converters/QuerySuggestionBoxConverter.cs @@ -11,14 +11,12 @@ public class QuerySuggestionBoxConverter : IMultiValueConverter { public object Convert(object[] values, Type targetType, object parameter, CultureInfo culture) { - if (values.Length != 3) + if (values.Length != 2) { return string.Empty; } - var QueryText = values[1] as TextBox; - var Suggestion = values[0] as TextBox; - Suggestion.CaretIndex = QueryText.CaretIndex; - Suggestion.ScrollToHorizontalOffset(QueryText.HorizontalOffset); + var QueryText = values[0] as TextBox; + // first prop is the current query string var queryText = QueryText.Text; @@ -27,7 +25,7 @@ public object Convert(object[] values, Type targetType, object parameter, Cultur return string.Empty; // second prop is the current selected item result - var val = values[2]; + var val = values[1]; if (val == null) { return string.Empty; @@ -45,7 +43,7 @@ public object Convert(object[] values, Type targetType, object parameter, Cultur var selectedResultActionKeyword = string.IsNullOrEmpty(selectedResult.ActionKeywordAssigned) ? "" : selectedResult.ActionKeywordAssigned + " "; var selectedResultPossibleSuggestion = selectedResultActionKeyword + selectedResult.Title; - if (!selectedResultPossibleSuggestion.StartsWith(queryText, StringComparison.CurrentCultureIgnoreCase)) + if (!selectedResultPossibleSuggestion.StartsWith(queryText, StringComparison.CurrentCultureIgnoreCase) || QueryText.HorizontalOffset != 0) return string.Empty; // When user typed lower case and result title is uppercase, we still want to display suggestion diff --git a/Flow.Launcher/MainWindow.xaml b/Flow.Launcher/MainWindow.xaml index 66278905ffd..9c74e417b7c 100644 --- a/Flow.Launcher/MainWindow.xaml +++ b/Flow.Launcher/MainWindow.xaml @@ -161,7 +161,6 @@ Style="{DynamicResource QuerySuggestionBoxStyle}"> - From a1789d7bf82265b7416eb416b1ace2d4395d81a7 Mon Sep 17 00:00:00 2001 From: Garulf <535299+Garulf@users.noreply.github.com> Date: Sat, 4 Dec 2021 18:19:09 -0500 Subject: [PATCH 07/12] Push Text path --- Flow.Launcher/Converters/QuerySuggestionBoxConverter.cs | 4 ++-- Flow.Launcher/MainWindow.xaml | 1 + 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/Flow.Launcher/Converters/QuerySuggestionBoxConverter.cs b/Flow.Launcher/Converters/QuerySuggestionBoxConverter.cs index bfff2782934..64b47833d9b 100644 --- a/Flow.Launcher/Converters/QuerySuggestionBoxConverter.cs +++ b/Flow.Launcher/Converters/QuerySuggestionBoxConverter.cs @@ -11,7 +11,7 @@ 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; } @@ -19,7 +19,7 @@ public object Convert(object[] values, Type targetType, object parameter, Cultur // first prop is the current query string - var queryText = QueryText.Text; + var queryText = (string)values[2]; if (string.IsNullOrEmpty(queryText)) return string.Empty; diff --git a/Flow.Launcher/MainWindow.xaml b/Flow.Launcher/MainWindow.xaml index 9c74e417b7c..acfa964060f 100644 --- a/Flow.Launcher/MainWindow.xaml +++ b/Flow.Launcher/MainWindow.xaml @@ -163,6 +163,7 @@ + From f24c14183cb8f535a55f80f56549e4c3f47d4d99 Mon Sep 17 00:00:00 2001 From: Garulf <535299+Garulf@users.noreply.github.com> Date: Sat, 4 Dec 2021 20:16:23 -0500 Subject: [PATCH 08/12] Change mode to OneWay --- Flow.Launcher/Converters/QuerySuggestionBoxConverter.cs | 6 +++--- Flow.Launcher/MainWindow.xaml | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/Flow.Launcher/Converters/QuerySuggestionBoxConverter.cs b/Flow.Launcher/Converters/QuerySuggestionBoxConverter.cs index 64b47833d9b..e68098c4980 100644 --- a/Flow.Launcher/Converters/QuerySuggestionBoxConverter.cs +++ b/Flow.Launcher/Converters/QuerySuggestionBoxConverter.cs @@ -11,15 +11,15 @@ public class QuerySuggestionBoxConverter : IMultiValueConverter { public object Convert(object[] values, Type targetType, object parameter, CultureInfo culture) { - if (values.Length != 3) + if (values.Length != 2) { return string.Empty; } var QueryText = values[0] as TextBox; - // first prop is the current query string - var queryText = (string)values[2]; + + var queryText = QueryText.Text; if (string.IsNullOrEmpty(queryText)) return string.Empty; diff --git a/Flow.Launcher/MainWindow.xaml b/Flow.Launcher/MainWindow.xaml index acfa964060f..29df0f9ae48 100644 --- a/Flow.Launcher/MainWindow.xaml +++ b/Flow.Launcher/MainWindow.xaml @@ -161,7 +161,7 @@ Style="{DynamicResource QuerySuggestionBoxStyle}"> - + From 8b33ca9a416693899e2ae0d7b1929e10603236c9 Mon Sep 17 00:00:00 2001 From: Garulf <535299+Garulf@users.noreply.github.com> Date: Sat, 4 Dec 2021 20:34:40 -0500 Subject: [PATCH 09/12] Use text path --- .../Converters/QuerySuggestionBoxConverter.cs | 10 ++++------ Flow.Launcher/MainWindow.xaml | 2 +- 2 files changed, 5 insertions(+), 7 deletions(-) diff --git a/Flow.Launcher/Converters/QuerySuggestionBoxConverter.cs b/Flow.Launcher/Converters/QuerySuggestionBoxConverter.cs index e68098c4980..d6b0c12d7df 100644 --- a/Flow.Launcher/Converters/QuerySuggestionBoxConverter.cs +++ b/Flow.Launcher/Converters/QuerySuggestionBoxConverter.cs @@ -11,15 +11,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 QueryText = values[0] as TextBox; + var QueryTextBox = values[0] as TextBox; - - - var queryText = QueryText.Text; + var queryText = (string)values[2]; if (string.IsNullOrEmpty(queryText)) return string.Empty; @@ -43,7 +41,7 @@ public object Convert(object[] values, Type targetType, object parameter, Cultur var selectedResultActionKeyword = string.IsNullOrEmpty(selectedResult.ActionKeywordAssigned) ? "" : selectedResult.ActionKeywordAssigned + " "; var selectedResultPossibleSuggestion = selectedResultActionKeyword + selectedResult.Title; - if (!selectedResultPossibleSuggestion.StartsWith(queryText, StringComparison.CurrentCultureIgnoreCase) || QueryText.HorizontalOffset != 0) + if (!selectedResultPossibleSuggestion.StartsWith(queryText, StringComparison.CurrentCultureIgnoreCase) || QueryTextBox.HorizontalOffset != 0) return string.Empty; // When user typed lower case and result title is uppercase, we still want to display suggestion diff --git a/Flow.Launcher/MainWindow.xaml b/Flow.Launcher/MainWindow.xaml index 29df0f9ae48..acfa964060f 100644 --- a/Flow.Launcher/MainWindow.xaml +++ b/Flow.Launcher/MainWindow.xaml @@ -161,7 +161,7 @@ Style="{DynamicResource QuerySuggestionBoxStyle}"> - + From 1dd9e2c3d2f9ed3cb518526755bcc0063f65315a Mon Sep 17 00:00:00 2001 From: Garulf <535299+Garulf@users.noreply.github.com> Date: Sun, 5 Dec 2021 10:42:58 -0500 Subject: [PATCH 10/12] Calculate if text font is larger then area --- .../Converters/QuerySuggestionBoxConverter.cs | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/Flow.Launcher/Converters/QuerySuggestionBoxConverter.cs b/Flow.Launcher/Converters/QuerySuggestionBoxConverter.cs index 9ee71a7def1..c457959e6d7 100644 --- a/Flow.Launcher/Converters/QuerySuggestionBoxConverter.cs +++ b/Flow.Launcher/Converters/QuerySuggestionBoxConverter.cs @@ -2,6 +2,7 @@ using System.Globalization; using System.Windows.Controls; using System.Windows.Data; +using System.Windows.Media; using Flow.Launcher.Infrastructure.Logger; using Flow.Launcher.ViewModel; @@ -41,13 +42,21 @@ public object Convert(object[] values, Type targetType, object parameter, Cultur var selectedResultActionKeyword = string.IsNullOrEmpty(selectedResult.ActionKeywordAssigned) ? "" : selectedResult.ActionKeywordAssigned + " "; var selectedResultPossibleSuggestion = selectedResultActionKeyword + selectedResult.Title; - if (!selectedResultPossibleSuggestion.StartsWith(queryText, StringComparison.CurrentCultureIgnoreCase) || QueryTextBox.HorizontalOffset != 0) + 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); - + + 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) + { + return string.Empty; + }; + return selectedItem.QuerySuggestionText; } catch (Exception e) From ef76b96dc5c77d69039167ab6b9a5dad980dea49 Mon Sep 17 00:00:00 2001 From: Garulf <535299+Garulf@users.noreply.github.com> Date: Sun, 5 Dec 2021 11:16:32 -0500 Subject: [PATCH 11/12] Check for offset --- Flow.Launcher/Converters/QuerySuggestionBoxConverter.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Flow.Launcher/Converters/QuerySuggestionBoxConverter.cs b/Flow.Launcher/Converters/QuerySuggestionBoxConverter.cs index c457959e6d7..e7d560f83b4 100644 --- a/Flow.Launcher/Converters/QuerySuggestionBoxConverter.cs +++ b/Flow.Launcher/Converters/QuerySuggestionBoxConverter.cs @@ -42,7 +42,7 @@ public object Convert(object[] values, Type targetType, object parameter, Cultur var selectedResultActionKeyword = string.IsNullOrEmpty(selectedResult.ActionKeywordAssigned) ? "" : selectedResult.ActionKeywordAssigned + " "; var selectedResultPossibleSuggestion = selectedResultActionKeyword + selectedResult.Title; - if (!selectedResultPossibleSuggestion.StartsWith(queryText, StringComparison.CurrentCultureIgnoreCase)) + if (!selectedResultPossibleSuggestion.StartsWith(queryText, StringComparison.CurrentCultureIgnoreCase) || QueryTextBox.HorizontalOffset != 0) return string.Empty; From 3282f8531a4de4b94b23d85c51f90cfb6ffdb5ef Mon Sep 17 00:00:00 2001 From: Garulf <535299+Garulf@users.noreply.github.com> Date: Sun, 5 Dec 2021 14:13:53 -0500 Subject: [PATCH 12/12] Add checks after suggestion is calculated --- Flow.Launcher/Converters/QuerySuggestionBoxConverter.cs | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/Flow.Launcher/Converters/QuerySuggestionBoxConverter.cs b/Flow.Launcher/Converters/QuerySuggestionBoxConverter.cs index e7d560f83b4..08ee8571e67 100644 --- a/Flow.Launcher/Converters/QuerySuggestionBoxConverter.cs +++ b/Flow.Launcher/Converters/QuerySuggestionBoxConverter.cs @@ -42,7 +42,7 @@ public object Convert(object[] values, Type targetType, object parameter, Cultur var selectedResultActionKeyword = string.IsNullOrEmpty(selectedResult.ActionKeywordAssigned) ? "" : selectedResult.ActionKeywordAssigned + " "; var selectedResultPossibleSuggestion = selectedResultActionKeyword + selectedResult.Title; - if (!selectedResultPossibleSuggestion.StartsWith(queryText, StringComparison.CurrentCultureIgnoreCase) || QueryTextBox.HorizontalOffset != 0) + if (!selectedResultPossibleSuggestion.StartsWith(queryText, StringComparison.CurrentCultureIgnoreCase)) return string.Empty; @@ -50,9 +50,10 @@ public object Convert(object[] values, Type targetType, object parameter, Cultur // 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) + if (ft.Width > QueryTextBox.ActualWidth || QueryTextBox.HorizontalOffset != 0) { return string.Empty; };