Browse Source

Ignore white spaces in search

CPKreuz 2 years ago
parent
commit
9f74167a6d

+ 1 - 1
src/PixiEditor/Models/Commands/Search/SearchResult.cs

@@ -51,7 +51,7 @@ internal abstract class SearchResult : NotifyableObject
 
     private IEnumerable<Inline> GetInlines()
     {
-        if (Match == null)
+        if (Match is not { Success: true })
         {
             yield return new Run(Text);
             yield break;

+ 4 - 14
src/PixiEditor/Views/UserControls/CommandSearch/CommandSearchControlHelper.cs

@@ -48,7 +48,7 @@ internal static class CommandSearchControlHelper
         // add matching commands
         newResults.AddRange(
             controller.Commands
-                .Where(x => x.Description.Contains(query, StringComparison.OrdinalIgnoreCase))
+                .Where(x => x.Description.Replace(" ", "").Contains(query, StringComparison.OrdinalIgnoreCase))
                 .Where(static x => ViewModelMain.Current.DebugSubViewModel.UseDebug ? true : !x.IsDebug)
                 .OrderByDescending(x => x.Description.Contains($" {query} ", StringComparison.OrdinalIgnoreCase))
                 .Take(18)
@@ -103,7 +103,7 @@ internal static class CommandSearchControlHelper
             files = files.Where(x => x.Contains(name, StringComparison.OrdinalIgnoreCase));
         }
 
-        var array = files as string[] ?? files.ToArray();
+        string[] array = files as string[] ?? files.ToArray();
         
         if (array.Length != 1)
         {
@@ -114,18 +114,8 @@ internal static class CommandSearchControlHelper
                     SearchTerm = name, Match = Match($".../{Path.GetFileName(path)}", name ?? "")
                 });
         }
-        else if (array.Length < 1)
-        {
-            return ArraySegment<SearchResult>.Empty;
-        }
-        else
-        {
-            return new[]
-            {
-                new FileSearchResult(array[0]),
-                new FileSearchResult(array[0], true)
-            };
-        }
+
+        return array.Length >= 1 ? new[] { new FileSearchResult(array[0]), new FileSearchResult(array[0], true) } : ArraySegment<SearchResult>.Empty;
     }
 
     private static bool GetDirectory(string path, out string directory, out string file)