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] 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 a459e9ee6..b9f3ba45b 100644 --- a/Flow.Launcher.Plugin/Result.cs +++ b/Flow.Launcher.Plugin/Result.cs @@ -257,6 +257,12 @@ namespace Flow.Launcher.Plugin /// 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 eb492e334..270dac4dc 100644 --- a/Flow.Launcher/Converters/QuerySuggestionBoxConverter.cs +++ b/Flow.Launcher/Converters/QuerySuggestionBoxConverter.cs @@ -33,15 +33,17 @@ public class QuerySuggestionBoxConverter : IMultiValueConverter { 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);