Skip to content

Commit 510eca1

Browse files
committed
Add config option for including the open generic results and tweak searchcontains slightly
1 parent 70a8fa3 commit 510eca1

2 files changed

Lines changed: 24 additions & 9 deletions

File tree

ComponentSelectorAdditions/SearchBar.cs

Lines changed: 15 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -98,25 +98,31 @@ public void Handle(EnumerateComponentsEvent eventData)
9898

9999
foreach (var result in results.TakeWhile(result => (!result.Component.HasGroup || knownGroups.Add(result.Component.Group) ? --remaining : remaining) >= 0))
100100
{
101-
eventData.AddItem(result.Component, result.Order);
102-
103-
if (result.Component.IsGeneric && parsedGeneric is not null)
101+
if (parsedGeneric is not null && result.Component.IsGeneric)
104102
{
105103
try
106104
{
107105
var concreteType = result.Component.Type.MakeGenericType(parsedGeneric);
108106

109-
if (!concreteType.IsValidGenericType(true))
110-
continue;
107+
if (concreteType.IsValidGenericType(true))
108+
{
109+
eventData.AddItem(new(result.Component.Category, concreteType), result.Order);
110+
111+
if (!ConfigSection.IncludeOpenGenericsWithGenericArgument)
112+
continue;
111113

112-
--remaining;
113-
eventData.AddItem(new(result.Component.Category, concreteType), result.Order);
114+
// Decrement remaining a further time for open generic below
115+
if (!result.Component.HasGroup)
116+
--remaining;
117+
}
114118
}
115119
catch (Exception ex)
116120
{
117-
Logger.Warn(ex.LogFormat($"Failed to make generic type for component [{result.Component.NiceName}] with [{parsedGeneric.GetNiceName()}] (from \"{eventData.Path.GenericType}\")!"));
121+
Logger.Debug(ex.LogFormat($"Failed to make generic type for component [{result.Component.NiceName}] with [{parsedGeneric.GetNiceName()}] (from \"{eventData.Path.SearchGeneric}\")!"));
118122
}
119123
}
124+
125+
eventData.AddItem(result.Component, result.Order);
120126
}
121127

122128
eventData.Canceled = true;
@@ -169,7 +175,7 @@ private static IEnumerable<CategoryNode<Type>> SearchCategories(CategoryNode<Typ
169175
}
170176

171177
private static int SearchContains(string haystack, string[] needles)
172-
=> needles.Count(needle => CultureInfo.InvariantCulture.CompareInfo.IndexOf(haystack, needle, CompareOptions.IgnoreCase) >= 0);
178+
=> needles.Count(needle => haystack.IndexOf(needle, 0, StringComparison.OrdinalIgnoreCase) >= 0);
173179

174180
private CategoryNode<Type> PickSearchCategory(IEnumerateSelectorResultEvent eventData)
175181
{

ComponentSelectorAdditions/SearchConfig.cs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,8 @@ public sealed class SearchConfig : SingletonConfigSection<SearchConfig>
2424

2525
private static readonly Dictionary<string, bool> _excludedCategories = new(StringComparer.OrdinalIgnoreCase);
2626

27+
private static readonly DefiningConfigKey<bool> _includeOpenGenericsWithGenericArgument = new("IncludeOpenGenericsWithGenericArgument", "Include the open generic versions of components / nodes in the results even when the generic argument can be applied to them successfully.", () => false);
28+
2729
private static readonly DefiningConfigKey<int> _maxResultCount = new("MaxResultCount", "The maximum number of component / node results to display. 'Better' results are listed first. Categories don't count.", () => 64)
2830
{
2931
new ConfigKeyRange<int>(1, 128)
@@ -35,6 +37,7 @@ public sealed class SearchConfig : SingletonConfigSection<SearchConfig>
3537
};
3638

3739
private static readonly DefiningConfigKey<string> _userExcludedCategories = new("UserExcludedCategories", "Excludes specific categories from being searched into by path (case sensitive). Separate entries by semicolon. Search will work when started inside them.", () => "/ProtoFlux");
40+
3841
private static readonly char[] _userExclusionSeparator = new[] { ';' };
3942

4043
/// <summary>
@@ -48,6 +51,12 @@ public sealed class SearchConfig : SingletonConfigSection<SearchConfig>
4851
/// <inheritdoc/>
4952
public override string Id => "Search";
5053

54+
/// <summary>
55+
/// Gets whether the open generic versions of components / nodes should be included in the results
56+
/// even when the generic argument can be applied to them successfully.
57+
/// </summary>
58+
public bool IncludeOpenGenericsWithGenericArgument => _includeOpenGenericsWithGenericArgument;
59+
5160
/// <summary>
5261
/// Gets how many results will be listed at most.
5362
/// </summary>

0 commit comments

Comments
 (0)