1
0
mirror of https://github.com/ppy/osu.git synced 2024-11-13 16:13:34 +08:00

Trim full phrase filters in a more precise manner

This commit is contained in:
Bartłomiej Dach 2023-06-27 21:34:49 +02:00
parent aba380b001
commit bf99fc61b8
No known key found for this signature in database
2 changed files with 14 additions and 10 deletions

View File

@ -76,8 +76,8 @@ namespace osu.Game.Tests.NonVisual.Filtering
Assert.AreEqual("\"!", filterCriteria.SearchText);
Assert.AreEqual(1, filterCriteria.SearchTerms.Length);
Assert.That(filterCriteria.SearchTerms[0].SearchTerm, Is.EqualTo("\"!"));
Assert.That(filterCriteria.SearchTerms[0].MatchMode, Is.EqualTo(FilterCriteria.MatchMode.Substring));
Assert.That(filterCriteria.SearchTerms[0].SearchTerm, Is.EqualTo("!"));
Assert.That(filterCriteria.SearchTerms[0].MatchMode, Is.EqualTo(FilterCriteria.MatchMode.IsolatedPhrase));
}
/*

View File

@ -174,15 +174,19 @@ namespace osu.Game.Screens.Select
{
searchTerm = value;
if (searchTerm.EndsWith("\"!", StringComparison.Ordinal))
if (searchTerm.StartsWith('\"'))
{
searchTerm = searchTerm.Trim('!', '\"');
MatchMode = MatchMode.FullPhrase;
}
else if (searchTerm.StartsWith('\"'))
{
searchTerm = searchTerm.Trim('\"');
MatchMode = MatchMode.IsolatedPhrase;
// length check ensures that the quote character in the `StartsWith()` check above and the `EndsWith()` check below is not the same character.
if (searchTerm.EndsWith("\"!", StringComparison.Ordinal) && searchTerm.Length >= 3)
{
searchTerm = searchTerm.TrimEnd('!').Trim('\"');
MatchMode = MatchMode.FullPhrase;
}
else
{
searchTerm = searchTerm.Trim('\"');
MatchMode = MatchMode.IsolatedPhrase;
}
}
else
MatchMode = MatchMode.Substring;