Merge pull request #850 from Garulf/global-tab-complete

Global TAB complete
This commit is contained in:
Garulf 2021-12-05 08:23:33 -05:00 committed by GitHub
commit 06a76f53dc
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
5 changed files with 44 additions and 4 deletions

View file

@ -29,6 +29,13 @@ namespace Flow.Launcher.Plugin
/// </summary>
public string ActionKeywordAssigned { get; set; }
/// <summary>
/// This holds the text which can be provided by plugin to help Flow autocomplete text
/// 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>
public string AutoCompleteText { get; set; }
public string IcoPath
{
get { return _icoPath; }

View file

@ -43,8 +43,11 @@ namespace Flow.Launcher.Converters
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
return queryText + selectedResultPossibleSuggestion.Substring(queryText.Length);
selectedItem.QuerySuggestionText = queryText + selectedResultPossibleSuggestion.Substring(queryText.Length);
return selectedItem.QuerySuggestionText;
}
catch (Exception e)
{

View file

@ -41,10 +41,12 @@
<KeyBinding Key="Escape" Command="{Binding EscCommand}" />
<KeyBinding Key="F1" Command="{Binding StartHelpCommand}" />
<KeyBinding Key="F5" Command="{Binding ReloadPluginDataCommand}" />
<KeyBinding Key="Tab" Command="{Binding SelectNextItemCommand}" />
<KeyBinding
Key="Tab"
Command="{Binding SelectPrevItemCommand}"
Command="{Binding AutocompleteQueryCommand}"/>
<KeyBinding
Key="Tab"
Command="{Binding AutocompleteQueryCommand}"
Modifiers="Shift" />
<KeyBinding
Key="I"

View file

@ -228,6 +228,32 @@ namespace Flow.Launcher.ViewModel
}
});
AutocompleteQueryCommand = new RelayCommand(_ =>
{
var result = SelectedResults.SelectedItem?.Result;
if (result != null) // SelectedItem returns null if selection is empty.
{
var autoCompleteText = result.Title;
if (!string.IsNullOrEmpty(result.AutoCompleteText))
{
autoCompleteText = result.AutoCompleteText;
}
else if (!string.IsNullOrEmpty(SelectedResults.SelectedItem?.QuerySuggestionText))
{
autoCompleteText = SelectedResults.SelectedItem.QuerySuggestionText;
}
var SpecialKeyState = GlobalHotkey.Instance.CheckModifiers();
if (SpecialKeyState.ShiftPressed)
{
autoCompleteText = result.SubTitle;
}
ChangeQueryText(autoCompleteText);
}
});
LoadContextMenuCommand = new RelayCommand(_ =>
{
if (SelectedIsFromQueryResults())
@ -287,7 +313,6 @@ namespace Flow.Launcher.ViewModel
public bool GameModeStatus { get; set; }
private string _queryText;
public string QueryText
{
get => _queryText;
@ -383,6 +408,7 @@ namespace Flow.Launcher.ViewModel
public ICommand OpenSettingCommand { get; set; }
public ICommand ReloadPluginDataCommand { get; set; }
public ICommand ClearQueryCommand { get; private set; }
public ICommand AutocompleteQueryCommand { get; set; }
public string OpenResultCommandModifiers { get; private set; }

View file

@ -142,6 +142,8 @@ namespace Flow.Launcher.ViewModel
public Result Result { get; }
public string QuerySuggestionText { get; set; }
public override bool Equals(object obj)
{
return obj is ResultViewModel r && Result.Equals(r.Result);