1
0
mirror of https://github.com/ppy/osu.git synced 2024-11-14 15:17:27 +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("\"!", filterCriteria.SearchText);
Assert.AreEqual(1, filterCriteria.SearchTerms.Length); Assert.AreEqual(1, filterCriteria.SearchTerms.Length);
Assert.That(filterCriteria.SearchTerms[0].SearchTerm, Is.EqualTo("\"!")); Assert.That(filterCriteria.SearchTerms[0].SearchTerm, Is.EqualTo("!"));
Assert.That(filterCriteria.SearchTerms[0].MatchMode, Is.EqualTo(FilterCriteria.MatchMode.Substring)); Assert.That(filterCriteria.SearchTerms[0].MatchMode, Is.EqualTo(FilterCriteria.MatchMode.IsolatedPhrase));
} }
/* /*

View File

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