Skip to content

Commit d8ef491

Browse files
authored
Merge pull request #3899 from Flow-Launcher/QuerySuggestionText_API
Add new api Result.QuerySuggestionText
2 parents a9b5b3a + bf07f2e commit d8ef491

File tree

2 files changed

+45
-6
lines changed

2 files changed

+45
-6
lines changed

Flow.Launcher.Plugin/Result.cs

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

6366
/// <summary>
@@ -257,6 +260,17 @@ public string PluginDirectory
257260
/// </summary>
258261
public bool ShowBadge { get; set; } = false;
259262

263+
/// <summary>
264+
/// This holds the text which can be shown as a query suggestion.
265+
/// </summary>
266+
/// <remarks>
267+
/// When a value is not set, the <see cref="Title"/> will be used.
268+
/// Do not include the action keyword prefix because Flow prepends it automatically.
269+
/// If the it does not start with the query text, it will not be shown as a suggestion.
270+
/// So make sure to set this value to start with the query text.
271+
/// </remarks>
272+
public string QuerySuggestionText { get; set; }
273+
260274
/// <summary>
261275
/// Run this result, asynchronously
262276
/// </summary>
@@ -307,7 +321,8 @@ public Result Clone()
307321
Preview = Preview,
308322
AddSelectedCount = AddSelectedCount,
309323
RecordKey = RecordKey,
310-
ShowBadge = ShowBadge
324+
ShowBadge = ShowBadge,
325+
QuerySuggestionText = QuerySuggestionText
311326
};
312327
}
313328

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)