diff --git a/src/modules/launcher/Wox/ViewModel/MainViewModel.cs b/src/modules/launcher/Wox/ViewModel/MainViewModel.cs index e28c318f05..eecce22a6f 100644 --- a/src/modules/launcher/Wox/ViewModel/MainViewModel.cs +++ b/src/modules/launcher/Wox/ViewModel/MainViewModel.cs @@ -152,35 +152,38 @@ namespace Wox.ViewModel results.SelectedIndex = int.Parse(index.ToString()); } - //If there is a context button selected fire the action for that button before the main command. - bool didExecuteContextButton = results.SelectedItem?.ExecuteSelectedContextButton() ?? false; - - if (!didExecuteContextButton) + if(results.SelectedItem != null) { - var result = results.SelectedItem?.Result; - if (result != null) // SelectedItem returns null if selection is empty. - { - bool hideWindow = result.Action != null && result.Action(new ActionContext - { - SpecialKeyState = GlobalHotkey.Instance.CheckModifiers() - }); - - if (hideWindow) - { - MainWindowVisibility = Visibility.Collapsed; - } - - if (SelectedIsFromQueryResults()) - { - _userSelectedRecord.Add(result); - _history.Add(result.OriginQuery.RawQuery); - } - else - { - SelectedResults = Results; - } - } - } + //If there is a context button selected fire the action for that button before the main command. + bool didExecuteContextButton = results.SelectedItem?.ExecuteSelectedContextButton() ?? false; + + if (!didExecuteContextButton) + { + var result = results.SelectedItem?.Result; + if (result != null) // SelectedItem returns null if selection is empty. + { + bool hideWindow = result.Action != null && result.Action(new ActionContext + { + SpecialKeyState = GlobalHotkey.Instance.CheckModifiers() + }); + + if (hideWindow) + { + MainWindowVisibility = Visibility.Collapsed; + } + + if (SelectedIsFromQueryResults()) + { + _userSelectedRecord.Add(result); + _history.Add(result.OriginQuery.RawQuery); + } + else + { + SelectedResults = Results; + } + } + } + } }); LoadContextMenuCommand = new RelayCommand(_ => @@ -419,7 +422,8 @@ namespace Wox.ViewModel } else { - Results.Clear(); + Results.SelectedItem = null; + Results.Clear(); Results.Visbility = Visibility.Collapsed; } } diff --git a/src/modules/launcher/Wox/ViewModel/ResultsViewModel.cs b/src/modules/launcher/Wox/ViewModel/ResultsViewModel.cs index c4e7360f13..31ae50c545 100644 --- a/src/modules/launcher/Wox/ViewModel/ResultsViewModel.cs +++ b/src/modules/launcher/Wox/ViewModel/ResultsViewModel.cs @@ -65,6 +65,10 @@ namespace Wox.ViewModel _selectedItem = value; _selectedItem.ActivateContextButtons(ResultViewModel.ActivationType.Selection); } + else + { + _selectedItem = value; + } } }