mirror of
https://github.com/Flow-Launcher/Flow.Launcher.git
synced 2026-03-11 08:54:32 +00:00
Merge pull request #3899 from Flow-Launcher/QuerySuggestionText_API
Add new api Result.QuerySuggestionText
This commit is contained in:
commit
d8ef49139d
2 changed files with 45 additions and 6 deletions
|
|
@ -57,7 +57,10 @@ namespace Flow.Launcher.Plugin
|
|||
/// 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.
|
||||
/// </summary>
|
||||
/// <remarks>When a value is not set, the <see cref="Title"/> will be used.</remarks>
|
||||
/// <remarks>
|
||||
/// When a value is not set, the <see cref="Title"/> will be used.
|
||||
/// Please include the action keyword prefix when necessary because Flow does not prepend it automatically.
|
||||
/// </remarks>
|
||||
public string AutoCompleteText { get; set; }
|
||||
|
||||
/// <summary>
|
||||
|
|
@ -257,6 +260,17 @@ namespace Flow.Launcher.Plugin
|
|||
/// </summary>
|
||||
public bool ShowBadge { get; set; } = false;
|
||||
|
||||
/// <summary>
|
||||
/// This holds the text which can be shown as a query suggestion.
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// When a value is not set, the <see cref="Title"/> 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.
|
||||
/// </remarks>
|
||||
public string QuerySuggestionText { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Run this result, asynchronously
|
||||
/// </summary>
|
||||
|
|
@ -307,7 +321,8 @@ namespace Flow.Launcher.Plugin
|
|||
Preview = Preview,
|
||||
AddSelectedCount = AddSelectedCount,
|
||||
RecordKey = RecordKey,
|
||||
ShowBadge = ShowBadge
|
||||
ShowBadge = ShowBadge,
|
||||
QuerySuggestionText = QuerySuggestionText
|
||||
};
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -33,15 +33,39 @@ public class QuerySuggestionBoxConverter : IMultiValueConverter
|
|||
{
|
||||
var selectedResult = selectedItem.Result;
|
||||
var selectedResultActionKeyword = string.IsNullOrEmpty(selectedResult.ActionKeywordAssigned) ? "" : selectedResult.ActionKeywordAssigned + " ";
|
||||
var selectedResultPossibleSuggestion = selectedResultActionKeyword + selectedResult.Title;
|
||||
|
||||
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.
|
||||
// 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);
|
||||
|
|
|
|||
Loading…
Reference in a new issue