Skip to content
4 changes: 4 additions & 0 deletions Flow.Launcher.Plugin/Result.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ public class Result

private string _icoPath;

private string _insertText;

/// <summary>
/// Provides the title of the result. This is always required.
/// </summary>
Expand All @@ -29,6 +31,8 @@ public class Result
/// </summary>
public string ActionKeywordAssigned { get; set; }

public string SuggestionText { get; set; } = string.Empty;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

do we want to change this to 'AutoCompleteText' to be more specific? I didnt get what it is for on first glance until i read the code.

This is good btw, it will allow plugins to do their own autocomplete, as @onesounds have indicated, if we change how Explorer display Title and Subtitle result, this will allow Explorer to put its own autocompelete text


public string IcoPath
{
get { return _icoPath; }
Expand Down
6 changes: 6 additions & 0 deletions Flow.Launcher/Converters/QuerySuggestionBoxConverter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,12 @@ public object Convert(object[] values, Type targetType, object parameter, Cultur
return string.Empty;

// When user typed lower case and result title is uppercase, we still want to display suggestion

string _suggestion = queryText + selectedResultPossibleSuggestion.Substring(queryText.Length);
if (String.IsNullOrEmpty(selectedResult.SuggestionText))
{
selectedItem.Result.SuggestionText = _suggestion;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@taooceros will this modifying result cause results comparison issue afterwards?

Copy link
Member

@jjw24 jjw24 Dec 5, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Instead of using Result's initialised field to hold the new constructed suggestion string, use ResultViewModel instead. As a general rule we dont want to modify an object after it is constructed, otherwise it's hard to reason what state/information the object has.

}
return queryText + selectedResultPossibleSuggestion.Substring(queryText.Length);
}
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 InsertSuggestion}"/>
<KeyBinding
Key="Tab"
Command="{Binding InsertSuggestion}"
Modifiers="Shift" />
<KeyBinding
Key="I"
Expand Down
20 changes: 19 additions & 1 deletion Flow.Launcher/ViewModel/MainViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -228,6 +228,24 @@ private void InitializeKeyCommands()
}
});

InsertSuggestion = new RelayCommand(_ =>
{
var results = SelectedResults;

var result = results.SelectedItem?.Result;
if (result != null) // SelectedItem returns null if selection is empty.
{
string _newText = String.IsNullOrEmpty(result.SuggestionText) ? result.Title : result.SuggestionText;

var SpecialKeyState = GlobalHotkey.Instance.CheckModifiers();
if (SpecialKeyState.ShiftPressed)
{
_newText = result.SubTitle;
}
ChangeQueryText(_newText);
}
});

LoadContextMenuCommand = new RelayCommand(_ =>
{
if (SelectedIsFromQueryResults())
Expand Down Expand Up @@ -287,7 +305,6 @@ private void InitializeKeyCommands()
public bool GameModeStatus { get; set; }

private string _queryText;

public string QueryText
{
get => _queryText;
Expand Down Expand Up @@ -383,6 +400,7 @@ private ResultsViewModel SelectedResults
public ICommand OpenSettingCommand { get; set; }
public ICommand ReloadPluginDataCommand { get; set; }
public ICommand ClearQueryCommand { get; private set; }
public ICommand InsertSuggestion { get; set; }

public string OpenResultCommandModifiers { get; private set; }

Expand Down