From 2ba6ce9e874f80db739da756f79e8b6c3b759ed0 Mon Sep 17 00:00:00 2001 From: Jeremy Date: Sun, 5 Dec 2021 19:15:32 +1100 Subject: [PATCH] use ResultViewModel to hold constructed suggestion text instead --- .../Converters/QuerySuggestionBoxConverter.cs | 2 +- Flow.Launcher/ViewModel/MainViewModel.cs | 16 +++++++++++++--- Flow.Launcher/ViewModel/ResultViewModel.cs | 2 ++ 3 files changed, 16 insertions(+), 4 deletions(-) diff --git a/Flow.Launcher/Converters/QuerySuggestionBoxConverter.cs b/Flow.Launcher/Converters/QuerySuggestionBoxConverter.cs index 6aa1facbc..1890cba6e 100644 --- a/Flow.Launcher/Converters/QuerySuggestionBoxConverter.cs +++ b/Flow.Launcher/Converters/QuerySuggestionBoxConverter.cs @@ -46,7 +46,7 @@ namespace Flow.Launcher.Converters // construct autocomplete with suggestion string _suggestion = queryText + selectedResultPossibleSuggestion.Substring(queryText.Length); if (string.IsNullOrEmpty(selectedResult.AutoCompleteText)) - selectedItem.Result.AutoCompleteText = _suggestion; + selectedItem.QuerySuggestionText = _suggestion; // When user typed lower case and result title is uppercase, we still want to display suggestion return queryText + selectedResultPossibleSuggestion.Substring(queryText.Length); diff --git a/Flow.Launcher/ViewModel/MainViewModel.cs b/Flow.Launcher/ViewModel/MainViewModel.cs index 5cc9d7cad..6f87162d3 100644 --- a/Flow.Launcher/ViewModel/MainViewModel.cs +++ b/Flow.Launcher/ViewModel/MainViewModel.cs @@ -233,14 +233,24 @@ namespace Flow.Launcher.ViewModel var result = SelectedResults.SelectedItem?.Result; if (result != null) // SelectedItem returns null if selection is empty. { - string _newText = String.IsNullOrEmpty(result.AutoCompleteText) ? result.Title : result.AutoCompleteText; + 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) { - _newText = result.SubTitle; + autoCompleteText = result.SubTitle; } - ChangeQueryText(_newText); + + ChangeQueryText(autoCompleteText); } }); diff --git a/Flow.Launcher/ViewModel/ResultViewModel.cs b/Flow.Launcher/ViewModel/ResultViewModel.cs index ed3d842e3..908de0c09 100644 --- a/Flow.Launcher/ViewModel/ResultViewModel.cs +++ b/Flow.Launcher/ViewModel/ResultViewModel.cs @@ -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);