Skip to content

Commit 5d9a897

Browse files
committed
Have QuerySuggection converter handle suggestions
1 parent 9bc68fd commit 5d9a897

File tree

4 files changed

+32
-22
lines changed

4 files changed

+32
-22
lines changed

Flow.Launcher/Converters/QuerySuggestionBoxConverter.cs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,12 @@ public object Convert(object[] values, Type targetType, object parameter, Cultur
4444
return string.Empty;
4545

4646
// When user typed lower case and result title is uppercase, we still want to display suggestion
47+
48+
string _suggestion = queryText + selectedResultPossibleSuggestion.Substring(queryText.Length);
49+
if (String.IsNullOrEmpty(selectedResult.SuggestionText))
50+
{
51+
selectedItem.Result.SuggestionText = _suggestion;
52+
}
4753
return queryText + selectedResultPossibleSuggestion.Substring(queryText.Length);
4854
}
4955
catch (Exception e)

Flow.Launcher/MainWindow.xaml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,13 @@
4141
<KeyBinding Key="Escape" Command="{Binding EscCommand}" />
4242
<KeyBinding Key="F1" Command="{Binding StartHelpCommand}" />
4343
<KeyBinding Key="F5" Command="{Binding ReloadPluginDataCommand}" />
44+
<KeyBinding
45+
Key="Tab"
46+
Command="{Binding InsertSuggestion}"/>
47+
<KeyBinding
48+
Key="Tab"
49+
Command="{Binding InsertSuggestion}"
50+
Modifiers="Shift" />
4451
<KeyBinding
4552
Key="I"
4653
Command="{Binding OpenSettingCommand}"

Flow.Launcher/MainWindow.xaml.cs

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -469,10 +469,6 @@ private void OnKeyDown(object sender, KeyEventArgs e)
469469
e.Handled = true;
470470
}
471471
break;
472-
case Key.Tab:
473-
_viewModel.InsertSuggestion(QueryTextSuggestionBox.Text);
474-
e.Handled = true;
475-
break;
476472
default:
477473
break;
478474

Flow.Launcher/ViewModel/MainViewModel.cs

Lines changed: 19 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -228,6 +228,24 @@ private void InitializeKeyCommands()
228228
}
229229
});
230230

231+
InsertSuggestion = new RelayCommand(_ =>
232+
{
233+
var results = SelectedResults;
234+
235+
var result = results.SelectedItem?.Result;
236+
if (result != null) // SelectedItem returns null if selection is empty.
237+
{
238+
string _newText = String.IsNullOrEmpty(result.SuggestionText) ? result.Title : result.SuggestionText;
239+
240+
var SpecialKeyState = GlobalHotkey.Instance.CheckModifiers();
241+
if (SpecialKeyState.ShiftPressed)
242+
{
243+
_newText = result.SubTitle;
244+
}
245+
ChangeQueryText(_newText);
246+
}
247+
});
248+
231249
LoadContextMenuCommand = new RelayCommand(_ =>
232250
{
233251
if (SelectedIsFromQueryResults())
@@ -315,24 +333,7 @@ public void ChangeQueryText(string queryText, bool reQuery = false)
315333
}
316334
QueryTextCursorMovedToEnd = true;
317335
}
318-
public void InsertSuggestion(string suggestion)
319-
{
320-
var results = SelectedResults;
321-
322-
var result = results.SelectedItem?.Result;
323-
if (result != null) // SelectedItem returns null if selection is empty.
324-
{
325-
suggestion = String.IsNullOrEmpty(suggestion) ? result.Title : suggestion;
326-
string _newText = String.IsNullOrEmpty(result.SuggestionText) ? suggestion : result.SuggestionText;
327336

328-
var SpecialKeyState = GlobalHotkey.Instance.CheckModifiers();
329-
if (SpecialKeyState.ShiftPressed)
330-
{
331-
_newText = result.SubTitle;
332-
}
333-
ChangeQueryText(_newText);
334-
}
335-
}
336337
public bool LastQuerySelected { get; set; }
337338

338339
// This is not a reliable indicator of the cursor's position, it is manually set for a specific purpose.
@@ -399,7 +400,7 @@ private ResultsViewModel SelectedResults
399400
public ICommand OpenSettingCommand { get; set; }
400401
public ICommand ReloadPluginDataCommand { get; set; }
401402
public ICommand ClearQueryCommand { get; private set; }
402-
public ICommand ReplaceQueryWithResult { get; set; }
403+
public ICommand InsertSuggestion { get; set; }
403404

404405
public string OpenResultCommandModifiers { get; private set; }
405406

0 commit comments

Comments
 (0)