Fix autocomplete text issue on query change (#7392)

* Fix autocomplete text issue on query change

* Update from invariant to ordinal case for exact byte to byte matching

* Add tests for checking when autocomplete should be empty
This commit is contained in:
Divyansh Srivastava
2020-10-20 14:53:32 -07:00
committed by GitHub
parent 0314b570cd
commit 466ed10f3d
3 changed files with 72 additions and 3 deletions

View File

@@ -871,13 +871,25 @@ namespace PowerLauncher.ViewModel
}
}
public static bool ShouldAutoCompleteTextBeEmpty(string queryText, string autoCompleteText)
{
if (string.IsNullOrEmpty(autoCompleteText))
{
return false;
}
else
{
return string.IsNullOrEmpty(queryText) || autoCompleteText.IndexOf(queryText, StringComparison.Ordinal) != 0;
}
}
public static string GetAutoCompleteText(int index, string input, string query)
{
if (!string.IsNullOrEmpty(input) && !string.IsNullOrEmpty(query))
{
if (index == 0)
{
if (input.IndexOf(query, StringComparison.InvariantCultureIgnoreCase) == 0)
if (input.IndexOf(query, StringComparison.OrdinalIgnoreCase) == 0)
{
// Use the same case as the input query for the matched portion of the string
return query + input.Substring(query.Length);
@@ -894,7 +906,7 @@ namespace PowerLauncher.ViewModel
{
if (index == 0 && !string.IsNullOrEmpty(query))
{
if (input.IndexOf(query, StringComparison.InvariantCultureIgnoreCase) == 0)
if (input.IndexOf(query, StringComparison.OrdinalIgnoreCase) == 0)
{
return query + input.Substring(query.Length);
}