From 15b7b20500c7c3f3f0f6b857ce43ec289fdbbb15 Mon Sep 17 00:00:00 2001 From: ryanbodrug-microsoft <56318517+ryanbodrug-microsoft@users.noreply.github.com> Date: Fri, 24 Apr 2020 08:30:11 -0700 Subject: [PATCH] - Fixes cursor jumping around issue. - Seperating the ability to set the text from initiating a query. - Plugins have to explicitly request the query be updated. - Updating Folder plugin to explicty update the query on folder selection. - Removing unused changes from 'Wox' that don't compile. --- .../Plugins/Wox.Plugin.Folder/Main.cs | 6 ++-- .../launcher/PowerLauncher/MainWindow.xaml.cs | 20 ++++++++----- src/modules/launcher/Wox/MainWindow.xaml.cs | 9 +----- src/modules/launcher/Wox/PublicAPIInstance.cs | 4 +-- .../launcher/Wox/ViewModel/MainViewModel.cs | 30 +++++++++---------- 5 files changed, 33 insertions(+), 36 deletions(-) diff --git a/src/modules/launcher/Plugins/Wox.Plugin.Folder/Main.cs b/src/modules/launcher/Plugins/Wox.Plugin.Folder/Main.cs index 2bde1a9245..12296056f8 100644 --- a/src/modules/launcher/Plugins/Wox.Plugin.Folder/Main.cs +++ b/src/modules/launcher/Plugins/Wox.Plugin.Folder/Main.cs @@ -112,9 +112,9 @@ namespace Wox.Plugin.Folder } string changeTo = path.EndsWith("\\") ? path : path + "\\"; - _context.API.ChangeQuery(string.IsNullOrEmpty(query.ActionKeyword) ? - changeTo : - query.ActionKeyword + " " + changeTo); + changeTo = string.IsNullOrEmpty(query.ActionKeyword) ? changeTo : query.ActionKeyword + " " + changeTo; + bool requery = true; + _context.API.ChangeQuery(changeTo, requery); return false; }, ContextData = new SearchResult { Type = ResultType.Folder, FullPath = path } diff --git a/src/modules/launcher/PowerLauncher/MainWindow.xaml.cs b/src/modules/launcher/PowerLauncher/MainWindow.xaml.cs index d84313ac00..5a56489cce 100644 --- a/src/modules/launcher/PowerLauncher/MainWindow.xaml.cs +++ b/src/modules/launcher/PowerLauncher/MainWindow.xaml.cs @@ -350,21 +350,25 @@ namespace PowerLauncher private void QueryTextBox_TextChanged(object sender, Windows.UI.Xaml.Controls.TextChangedEventArgs e) { - var latestTimeOfTyping = DateTime.Now; var text = ((Windows.UI.Xaml.Controls.TextBox)sender).Text; - Task.Run(() => DelayedCheck(latestTimeOfTyping, text)); - s_lastTimeOfTyping = latestTimeOfTyping; - //To clear the auto-suggest immediately instead of waiting for selection changed - if(text == String.Empty) + if (text == String.Empty) { _launcher.AutoCompleteTextBox.PlaceholderText = String.Empty; } - if (_viewModel.QueryTextCursorMovedToEnd) + if (_viewModel.QueryTextUpdateBySystem) { _launcher.TextBox.SelectionStart = _launcher.TextBox.Text.Length; - _viewModel.QueryTextCursorMovedToEnd = false; + _viewModel.QueryTextUpdateBySystem = false; + } + else + { + _viewModel.QueryText = text; + var latestTimeOfTyping = DateTime.Now; + + Task.Run(() => DelayedCheck(latestTimeOfTyping, text)); + s_lastTimeOfTyping = latestTimeOfTyping; } } @@ -375,7 +379,7 @@ namespace PowerLauncher { await System.Windows.Application.Current.Dispatcher.BeginInvoke(new Action(() => { - _viewModel.QueryText = text; + _viewModel.Query(); })); } } diff --git a/src/modules/launcher/Wox/MainWindow.xaml.cs b/src/modules/launcher/Wox/MainWindow.xaml.cs index e0ee4ef3f5..ed15aef699 100644 --- a/src/modules/launcher/Wox/MainWindow.xaml.cs +++ b/src/modules/launcher/Wox/MainWindow.xaml.cs @@ -235,16 +235,9 @@ namespace Wox e.Handled = true; } } - private void OnTextChanged(object sender, TextChangedEventArgs e) { - if (_viewModel.QueryTextCursorMovedToEnd) - { - QueryTextBox.CaretIndex = QueryTextBox.Text.Length; - _viewModel.QueryTextCursorMovedToEnd = false; - } + } - - } } \ No newline at end of file diff --git a/src/modules/launcher/Wox/PublicAPIInstance.cs b/src/modules/launcher/Wox/PublicAPIInstance.cs index 10c33b3b36..689f6b8c46 100644 --- a/src/modules/launcher/Wox/PublicAPIInstance.cs +++ b/src/modules/launcher/Wox/PublicAPIInstance.cs @@ -38,12 +38,12 @@ namespace Wox public void ChangeQuery(string query, bool requery = false) { - _mainVM.ChangeQueryText(query); + _mainVM.ChangeQueryText(query, requery); } public void ChangeQueryText(string query, bool selectAll = false) { - _mainVM.ChangeQueryText(query); + _mainVM.ChangeQueryText(query, false); } [Obsolete] diff --git a/src/modules/launcher/Wox/ViewModel/MainViewModel.cs b/src/modules/launcher/Wox/ViewModel/MainViewModel.cs index ffcdaf0d8e..e64ffba32d 100644 --- a/src/modules/launcher/Wox/ViewModel/MainViewModel.cs +++ b/src/modules/launcher/Wox/ViewModel/MainViewModel.cs @@ -51,7 +51,6 @@ namespace Wox.ViewModel { _saved = false; _queryTextBeforeLeaveResults = ""; - _queryText = ""; _lastQuery = new Query(); _settings = settings; @@ -223,29 +222,30 @@ namespace Wox.ViewModel public ResultsViewModel ContextMenu { get; private set; } public ResultsViewModel History { get; private set; } - private string _queryText; - public string QueryText - { - get { return _queryText; } - set - { - _queryText = value; - Query(); - } - } + public string SystemQueryText { get; set; } + + public string QueryText { get; set; } + /// /// we need move cursor to end when we manually changed query - /// but we don't want to move cursor to end when query is updated from TextBox + /// but we don't want to move cursor to end when query is updated from TextBox. + /// Also we don't want to force the results to change unless explicity told to. /// /// - public void ChangeQueryText(string queryText) + /// Optional Parameter that if true, will automatically execute a query against the updated text + public void ChangeQueryText(string queryText, bool requery=false) { - QueryTextCursorMovedToEnd = true; + QueryTextUpdateBySystem = true; QueryText = queryText; + + if(requery) + { + Query(); + } } public bool LastQuerySelected { get; set; } - public bool QueryTextCursorMovedToEnd { get; set; } + public bool QueryTextUpdateBySystem { get; set; } private ResultsViewModel _selectedResults; private ResultsViewModel SelectedResults