Skip to content

Commit 06a76f5

Browse files
authored
Merge pull request #850 from Garulf/global-tab-complete
Global TAB complete
2 parents 4f7e839 + 78dbc0c commit 06a76f5

File tree

5 files changed

+44
-4
lines changed

5 files changed

+44
-4
lines changed

Flow.Launcher.Plugin/Result.cs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,13 @@ public class Result
2929
/// </summary>
3030
public string ActionKeywordAssigned { get; set; }
3131

32+
/// <summary>
33+
/// This holds the text which can be provided by plugin to help Flow autocomplete text
34+
/// for user on the plugin result. If autocomplete action for example is tab, pressing tab will have
35+
/// the default constructed autocomplete text (result's Title), or the text provided here if not empty.
36+
/// </summary>
37+
public string AutoCompleteText { get; set; }
38+
3239
public string IcoPath
3340
{
3441
get { return _icoPath; }

Flow.Launcher/Converters/QuerySuggestionBoxConverter.cs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,8 +43,11 @@ public object Convert(object[] values, Type targetType, object parameter, Cultur
4343
if (!selectedResultPossibleSuggestion.StartsWith(queryText, StringComparison.CurrentCultureIgnoreCase))
4444
return string.Empty;
4545

46+
// For AutocompleteQueryCommand.
4647
// When user typed lower case and result title is uppercase, we still want to display suggestion
47-
return queryText + selectedResultPossibleSuggestion.Substring(queryText.Length);
48+
selectedItem.QuerySuggestionText = queryText + selectedResultPossibleSuggestion.Substring(queryText.Length);
49+
50+
return selectedItem.QuerySuggestionText;
4851
}
4952
catch (Exception e)
5053
{

Flow.Launcher/MainWindow.xaml

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,10 +41,12 @@
4141
<KeyBinding Key="Escape" Command="{Binding EscCommand}" />
4242
<KeyBinding Key="F1" Command="{Binding StartHelpCommand}" />
4343
<KeyBinding Key="F5" Command="{Binding ReloadPluginDataCommand}" />
44-
<KeyBinding Key="Tab" Command="{Binding SelectNextItemCommand}" />
4544
<KeyBinding
4645
Key="Tab"
47-
Command="{Binding SelectPrevItemCommand}"
46+
Command="{Binding AutocompleteQueryCommand}"/>
47+
<KeyBinding
48+
Key="Tab"
49+
Command="{Binding AutocompleteQueryCommand}"
4850
Modifiers="Shift" />
4951
<KeyBinding
5052
Key="I"

Flow.Launcher/ViewModel/MainViewModel.cs

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -228,6 +228,32 @@ private void InitializeKeyCommands()
228228
}
229229
});
230230

231+
AutocompleteQueryCommand = new RelayCommand(_ =>
232+
{
233+
var result = SelectedResults.SelectedItem?.Result;
234+
if (result != null) // SelectedItem returns null if selection is empty.
235+
{
236+
var autoCompleteText = result.Title;
237+
238+
if (!string.IsNullOrEmpty(result.AutoCompleteText))
239+
{
240+
autoCompleteText = result.AutoCompleteText;
241+
}
242+
else if (!string.IsNullOrEmpty(SelectedResults.SelectedItem?.QuerySuggestionText))
243+
{
244+
autoCompleteText = SelectedResults.SelectedItem.QuerySuggestionText;
245+
}
246+
247+
var SpecialKeyState = GlobalHotkey.Instance.CheckModifiers();
248+
if (SpecialKeyState.ShiftPressed)
249+
{
250+
autoCompleteText = result.SubTitle;
251+
}
252+
253+
ChangeQueryText(autoCompleteText);
254+
}
255+
});
256+
231257
LoadContextMenuCommand = new RelayCommand(_ =>
232258
{
233259
if (SelectedIsFromQueryResults())
@@ -287,7 +313,6 @@ private void InitializeKeyCommands()
287313
public bool GameModeStatus { get; set; }
288314

289315
private string _queryText;
290-
291316
public string QueryText
292317
{
293318
get => _queryText;
@@ -383,6 +408,7 @@ private ResultsViewModel SelectedResults
383408
public ICommand OpenSettingCommand { get; set; }
384409
public ICommand ReloadPluginDataCommand { get; set; }
385410
public ICommand ClearQueryCommand { get; private set; }
411+
public ICommand AutocompleteQueryCommand { get; set; }
386412

387413
public string OpenResultCommandModifiers { get; private set; }
388414

Flow.Launcher/ViewModel/ResultViewModel.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -142,6 +142,8 @@ private async ValueTask LoadImageAsync()
142142

143143
public Result Result { get; }
144144

145+
public string QuerySuggestionText { get; set; }
146+
145147
public override bool Equals(object obj)
146148
{
147149
return obj is ResultViewModel r && Result.Equals(r.Result);

0 commit comments

Comments
 (0)