From 8c6f9c9875d549f123fe938da425931e93fdf9c3 Mon Sep 17 00:00:00 2001 From: Jack251970 <1160210343@qq.com> Date: Wed, 13 Aug 2025 20:26:23 +0800 Subject: [PATCH 1/5] Add new api Result.QuerySuggestionText --- Flow.Launcher.Plugin/Result.cs | 6 ++++++ Flow.Launcher/Converters/QuerySuggestionBoxConverter.cs | 8 +++++--- 2 files changed, 11 insertions(+), 3 deletions(-) diff --git a/Flow.Launcher.Plugin/Result.cs b/Flow.Launcher.Plugin/Result.cs index a459e9ee663..b9f3ba45b2c 100644 --- a/Flow.Launcher.Plugin/Result.cs +++ b/Flow.Launcher.Plugin/Result.cs @@ -257,6 +257,12 @@ public string PluginDirectory /// public bool ShowBadge { get; set; } = false; + /// + /// This holds the text which can be shown as a query suggestion. + /// + /// When a value is not set, the will be used. + public string QuerySuggestionText { get; set; } + /// /// Run this result, asynchronously /// diff --git a/Flow.Launcher/Converters/QuerySuggestionBoxConverter.cs b/Flow.Launcher/Converters/QuerySuggestionBoxConverter.cs index eb492e3344e..270dac4dcea 100644 --- a/Flow.Launcher/Converters/QuerySuggestionBoxConverter.cs +++ b/Flow.Launcher/Converters/QuerySuggestionBoxConverter.cs @@ -33,15 +33,17 @@ values[2] is not string queryText || { var selectedResult = selectedItem.Result; var selectedResultActionKeyword = string.IsNullOrEmpty(selectedResult.ActionKeywordAssigned) ? "" : selectedResult.ActionKeywordAssigned + " "; - var selectedResultPossibleSuggestion = selectedResultActionKeyword + selectedResult.Title; + var selectedResultPossibleSuggestion = selectedResultActionKeyword + + (string.IsNullOrEmpty(selectedResult.QuerySuggestionText) ? + selectedResult.Title : + selectedResult.QuerySuggestionText); 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); + selectedItem.QuerySuggestionText = string.Concat(queryText, selectedResultPossibleSuggestion.AsSpan(queryText.Length)); // Check if Text will be larger than our QueryTextBox Typeface typeface = new Typeface(queryTextBox.FontFamily, queryTextBox.FontStyle, queryTextBox.FontWeight, queryTextBox.FontStretch); From 2a1584e2dd38815111cd927aba4876946989f7ab Mon Sep 17 00:00:00 2001 From: Jack251970 <1160210343@qq.com> Date: Wed, 13 Aug 2025 20:43:51 +0800 Subject: [PATCH 2/5] Add code comments --- Flow.Launcher.Plugin/Result.cs | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/Flow.Launcher.Plugin/Result.cs b/Flow.Launcher.Plugin/Result.cs index b9f3ba45b2c..76d3d7d345a 100644 --- a/Flow.Launcher.Plugin/Result.cs +++ b/Flow.Launcher.Plugin/Result.cs @@ -260,7 +260,11 @@ public string PluginDirectory /// /// This holds the text which can be shown as a query suggestion. /// - /// When a value is not set, the will be used. + /// + /// When a value is not set, the will be used. + /// If the it does not start with the query text, it will not be shown as a suggestion. + /// So make sure to set this value to start with the query text. + /// public string QuerySuggestionText { get; set; } /// From 063836266decfce8ed31ab7113b6d06b6b4c8d7e Mon Sep 17 00:00:00 2001 From: Jack251970 <1160210343@qq.com> Date: Wed, 13 Aug 2025 20:44:00 +0800 Subject: [PATCH 3/5] Fix Result.Clone --- Flow.Launcher.Plugin/Result.cs | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/Flow.Launcher.Plugin/Result.cs b/Flow.Launcher.Plugin/Result.cs index 76d3d7d345a..fb4313e367c 100644 --- a/Flow.Launcher.Plugin/Result.cs +++ b/Flow.Launcher.Plugin/Result.cs @@ -317,7 +317,8 @@ public Result Clone() Preview = Preview, AddSelectedCount = AddSelectedCount, RecordKey = RecordKey, - ShowBadge = ShowBadge + ShowBadge = ShowBadge, + QuerySuggestionText = QuerySuggestionText }; } From c895b2acb0cc0364067c5fd89b3e7f6cb62630a0 Mon Sep 17 00:00:00 2001 From: Jack251970 <1160210343@qq.com> Date: Wed, 13 Aug 2025 20:53:53 +0800 Subject: [PATCH 4/5] Improve selectedResultPossibleSuggestion check logic --- .../Converters/QuerySuggestionBoxConverter.cs | 32 ++++++++++++++++--- 1 file changed, 27 insertions(+), 5 deletions(-) diff --git a/Flow.Launcher/Converters/QuerySuggestionBoxConverter.cs b/Flow.Launcher/Converters/QuerySuggestionBoxConverter.cs index 270dac4dcea..c2d7d016ca4 100644 --- a/Flow.Launcher/Converters/QuerySuggestionBoxConverter.cs +++ b/Flow.Launcher/Converters/QuerySuggestionBoxConverter.cs @@ -33,12 +33,34 @@ values[2] is not string queryText || { var selectedResult = selectedItem.Result; var selectedResultActionKeyword = string.IsNullOrEmpty(selectedResult.ActionKeywordAssigned) ? "" : selectedResult.ActionKeywordAssigned + " "; - var selectedResultPossibleSuggestion = selectedResultActionKeyword + - (string.IsNullOrEmpty(selectedResult.QuerySuggestionText) ? - selectedResult.Title : - selectedResult.QuerySuggestionText); - if (!selectedResultPossibleSuggestion.StartsWith(queryText, StringComparison.CurrentCultureIgnoreCase)) + string selectedResultPossibleSuggestion = null; + + // Firstly check if the result has QuerySuggestionText + if (!string.IsNullOrEmpty(selectedResult.QuerySuggestionText)) + { + selectedResultPossibleSuggestion = selectedResultActionKeyword + selectedResult.QuerySuggestionText; + + // If this QuerySuggestionText does not start with the queryText, set it to null + if (!selectedResultPossibleSuggestion.StartsWith(queryText, StringComparison.CurrentCultureIgnoreCase)) + { + selectedResultPossibleSuggestion = null; + } + } + + // Then check Title as suggestion + if (string.IsNullOrEmpty(selectedResultPossibleSuggestion)) + { + selectedResultPossibleSuggestion = selectedResultActionKeyword + selectedResult.Title; + + // If this QuerySuggestionText does not start with the queryText, set it to null + if (!selectedResultPossibleSuggestion.StartsWith(queryText, StringComparison.CurrentCultureIgnoreCase)) + { + selectedResultPossibleSuggestion = null; + } + } + + if (string.IsNullOrEmpty(selectedResultPossibleSuggestion)) return string.Empty; // For AutocompleteQueryCommand. From bf07f2e72c9e4ffd660c8689cb478b99e291fe4f Mon Sep 17 00:00:00 2001 From: Jack251970 <1160210343@qq.com> Date: Wed, 13 Aug 2025 21:00:17 +0800 Subject: [PATCH 5/5] Improve xml documents --- Flow.Launcher.Plugin/Result.cs | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/Flow.Launcher.Plugin/Result.cs b/Flow.Launcher.Plugin/Result.cs index fb4313e367c..2c9b8d4fdbc 100644 --- a/Flow.Launcher.Plugin/Result.cs +++ b/Flow.Launcher.Plugin/Result.cs @@ -57,7 +57,10 @@ public string CopyText /// for user on the plugin result. If autocomplete action for example is tab, pressing tab will have /// the default constructed autocomplete text (result's Title), or the text provided here if not empty. /// - /// When a value is not set, the will be used. + /// + /// When a value is not set, the will be used. + /// Please include the action keyword prefix when necessary because Flow does not prepend it automatically. + /// public string AutoCompleteText { get; set; } /// @@ -262,6 +265,7 @@ public string PluginDirectory /// /// /// When a value is not set, the will be used. + /// Do not include the action keyword prefix because Flow prepends it automatically. /// If the it does not start with the query text, it will not be shown as a suggestion. /// So make sure to set this value to start with the query text. ///