Skip to content

Commit

Permalink
Merge pull request #850 from Garulf/global-tab-complete
Browse files Browse the repository at this point in the history
Global TAB complete
  • Loading branch information
Garulf authored Dec 5, 2021
2 parents 4f7e839 + 78dbc0c commit 06a76f5
Show file tree
Hide file tree
Showing 5 changed files with 44 additions and 4 deletions.
7 changes: 7 additions & 0 deletions Flow.Launcher.Plugin/Result.cs
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,13 @@ public class Result
/// </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; }
Expand Down
5 changes: 4 additions & 1 deletion Flow.Launcher/Converters/QuerySuggestionBoxConverter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,11 @@ public object Convert(object[] values, Type targetType, object parameter, Cultur
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)
{
Expand Down
6 changes: 4 additions & 2 deletions Flow.Launcher/MainWindow.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
28 changes: 27 additions & 1 deletion Flow.Launcher/ViewModel/MainViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -228,6 +228,32 @@ private void InitializeKeyCommands()
}
});

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())
Expand Down Expand Up @@ -287,7 +313,6 @@ private void InitializeKeyCommands()
public bool GameModeStatus { get; set; }

private string _queryText;

public string QueryText
{
get => _queryText;
Expand Down Expand Up @@ -383,6 +408,7 @@ private ResultsViewModel SelectedResults
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; }

Expand Down
2 changes: 2 additions & 0 deletions Flow.Launcher/ViewModel/ResultViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,8 @@ private async ValueTask LoadImageAsync()

public Result Result { get; }

public string QuerySuggestionText { get; set; }

public override bool Equals(object obj)
{
return obj is ResultViewModel r && Result.Equals(r.Result);
Expand Down

0 comments on commit 06a76f5

Please sign in to comment.