Skip to content

Commit cfb609b

Browse files
Jack251970TBM13
authored andcommitted
Merge pull request Flow-Launcher#3899 from Flow-Launcher/QuerySuggestionText_API
Add new api Result.QuerySuggestionText
1 parent 1127db7 commit cfb609b

File tree

2 files changed

+44
-5
lines changed

2 files changed

+44
-5
lines changed

Flow.Launcher.Plugin/Result.cs

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,10 @@ public string CopyText
5555
/// for user on the plugin result. If autocomplete action for example is tab, pressing tab will have
5656
/// the default constructed autocomplete text (result's Title), or the text provided here if not empty.
5757
/// </summary>
58-
/// <remarks>When a value is not set, the <see cref="Title"/> will be used.</remarks>
58+
/// <remarks>
59+
/// When a value is not set, the <see cref="Title"/> will be used.
60+
/// Please include the action keyword prefix when necessary because Flow does not prepend it automatically.
61+
/// </remarks>
5962
public string AutoCompleteText { get; set; }
6063

6164
/// <summary>
@@ -200,6 +203,17 @@ public string PluginDirectory
200203
/// </summary>
201204
public string RecordKey { get; set; } = null;
202205

206+
/// <summary>
207+
/// This holds the text which can be shown as a query suggestion.
208+
/// </summary>
209+
/// <remarks>
210+
/// When a value is not set, the <see cref="Title"/> will be used.
211+
/// Do not include the action keyword prefix because Flow prepends it automatically.
212+
/// If the it does not start with the query text, it will not be shown as a suggestion.
213+
/// So make sure to set this value to start with the query text.
214+
/// </remarks>
215+
public string QuerySuggestionText { get; set; }
216+
203217
/// <summary>
204218
/// Run this result, asynchronously
205219
/// </summary>
@@ -245,6 +259,7 @@ public Result Clone()
245259
Preview = Preview,
246260
AddSelectedCount = AddSelectedCount,
247261
RecordKey = RecordKey,
262+
QuerySuggestionText = QuerySuggestionText
248263
};
249264
}
250265

Flow.Launcher/Converters/QuerySuggestionBoxConverter.cs

Lines changed: 28 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -33,15 +33,39 @@ values[2] is not string queryText ||
3333
{
3434
var selectedResult = selectedItem.Result;
3535
var selectedResultActionKeyword = string.IsNullOrEmpty(selectedResult.ActionKeywordAssigned) ? "" : selectedResult.ActionKeywordAssigned + " ";
36-
var selectedResultPossibleSuggestion = selectedResultActionKeyword + selectedResult.Title;
3736

38-
if (!selectedResultPossibleSuggestion.StartsWith(queryText, StringComparison.CurrentCultureIgnoreCase))
39-
return string.Empty;
37+
string selectedResultPossibleSuggestion = null;
38+
39+
// Firstly check if the result has QuerySuggestionText
40+
if (!string.IsNullOrEmpty(selectedResult.QuerySuggestionText))
41+
{
42+
selectedResultPossibleSuggestion = selectedResultActionKeyword + selectedResult.QuerySuggestionText;
43+
44+
// If this QuerySuggestionText does not start with the queryText, set it to null
45+
if (!selectedResultPossibleSuggestion.StartsWith(queryText, StringComparison.CurrentCultureIgnoreCase))
46+
{
47+
selectedResultPossibleSuggestion = null;
48+
}
49+
}
50+
51+
// Then check Title as suggestion
52+
if (string.IsNullOrEmpty(selectedResultPossibleSuggestion))
53+
{
54+
selectedResultPossibleSuggestion = selectedResultActionKeyword + selectedResult.Title;
4055

56+
// If this QuerySuggestionText does not start with the queryText, set it to null
57+
if (!selectedResultPossibleSuggestion.StartsWith(queryText, StringComparison.CurrentCultureIgnoreCase))
58+
{
59+
selectedResultPossibleSuggestion = null;
60+
}
61+
}
62+
63+
if (string.IsNullOrEmpty(selectedResultPossibleSuggestion))
64+
return string.Empty;
4165

4266
// For AutocompleteQueryCommand.
4367
// When user typed lower case and result title is uppercase, we still want to display suggestion
44-
selectedItem.QuerySuggestionText = queryText + selectedResultPossibleSuggestion.Substring(queryText.Length);
68+
selectedItem.QuerySuggestionText = string.Concat(queryText, selectedResultPossibleSuggestion.AsSpan(queryText.Length));
4569

4670
// Check if Text will be larger than our QueryTextBox
4771
Typeface typeface = new Typeface(queryTextBox.FontFamily, queryTextBox.FontStyle, queryTextBox.FontWeight, queryTextBox.FontStretch);

0 commit comments

Comments
 (0)