diff --git a/Wox/MainWindow.xaml.cs b/Wox/MainWindow.xaml.cs
index de56fa027a..0110e87339 100644
--- a/Wox/MainWindow.xaml.cs
+++ b/Wox/MainWindow.xaml.cs
@@ -235,7 +235,11 @@ namespace Wox
private void OnTextChanged(object sender, TextChangedEventArgs e)
{
- QueryTextBox.CaretIndex = QueryTextBox.Text.Length;
+ if (_viewModel.QueryTextCursorMovedToEnd)
+ {
+ QueryTextBox.CaretIndex = QueryTextBox.Text.Length;
+ _viewModel.QueryTextCursorMovedToEnd = false;
+ }
}
}
}
\ No newline at end of file
diff --git a/Wox/PublicAPIInstance.cs b/Wox/PublicAPIInstance.cs
index e9801f686c..86f415727e 100644
--- a/Wox/PublicAPIInstance.cs
+++ b/Wox/PublicAPIInstance.cs
@@ -36,12 +36,12 @@ namespace Wox
public void ChangeQuery(string query, bool requery = false)
{
- _mainVM.QueryText = query;
+ _mainVM.ChangeQueryText(query);
}
public void ChangeQueryText(string query, bool selectAll = false)
{
- _mainVM.QueryText = query;
+ _mainVM.ChangeQueryText(query);
}
[Obsolete]
diff --git a/Wox/ViewModel/MainViewModel.cs b/Wox/ViewModel/MainViewModel.cs
index d5fa307f69..8cc43084c8 100644
--- a/Wox/ViewModel/MainViewModel.cs
+++ b/Wox/ViewModel/MainViewModel.cs
@@ -205,7 +205,19 @@ namespace Wox.ViewModel
Query();
}
}
+
+ ///
+ /// 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
+ ///
+ ///
+ public void ChangeQueryText(string queryText)
+ {
+ QueryTextCursorMovedToEnd = true;
+ QueryText = queryText;
+ }
public bool QueryTextSelected { get; set; }
+ public bool QueryTextCursorMovedToEnd { get; set; }
private ResultsViewModel _selectedResults;
private ResultsViewModel SelectedResults
@@ -218,7 +230,7 @@ namespace Wox.ViewModel
{
ContextMenu.Visbility = Visibility.Collapsed;
History.Visbility = Visibility.Collapsed;
- QueryText = _queryTextBeforeLeaveResults;
+ ChangeQueryText(_queryTextBeforeLeaveResults);
}
else
{
@@ -325,7 +337,7 @@ namespace Wox.ViewModel
Action = _ =>
{
SelectedResults = Results;
- QueryText = h.Query;
+ ChangeQueryText(h.Query);
return false;
}
};
@@ -547,7 +559,7 @@ namespace Wox.ViewModel
{
if (ShouldIgnoreHotkeys()) return;
MainWindowVisibility = Visibility.Visible;
- QueryText = hotkey.ActionKeyword;
+ ChangeQueryText(hotkey.ActionKeyword);
});
}
}