From 8045e0566f331e5573e174cb2d943bd29aa51797 Mon Sep 17 00:00:00 2001
From: Dean Herbert <pe@ppy.sh>
Date: Thu, 13 Jul 2017 12:22:51 +0900
Subject: [PATCH] Use a bindable for the current query.

Aso debounce and don't require hitting enter.
---
 osu.Game/Overlays/DirectOverlay.cs | 35 ++++++++++++++++++++++--------
 1 file changed, 26 insertions(+), 9 deletions(-)

diff --git a/osu.Game/Overlays/DirectOverlay.cs b/osu.Game/Overlays/DirectOverlay.cs
index 83f22c6ad8..df5955e7e6 100644
--- a/osu.Game/Overlays/DirectOverlay.cs
+++ b/osu.Game/Overlays/DirectOverlay.cs
@@ -5,6 +5,7 @@ using System.Collections.Generic;
 using System.Linq;
 using OpenTK;
 using osu.Framework.Allocation;
+using osu.Framework.Configuration;
 using osu.Framework.Graphics;
 using osu.Framework.Graphics.Containers;
 using osu.Framework.Threading;
@@ -124,18 +125,29 @@ namespace osu.Game.Overlays
             {
                 if (tab != DirectTab.Search)
                 {
-                    Filter.Search.Text = lastQuery = string.Empty;
+                    currentQuery.Value = string.Empty;
                     Filter.Tabs.Current.Value = (DirectSortCriteria)Header.Tabs.Current.Value;
                     Scheduler.AddOnce(updateSearch);
                 }
             };
 
-            Filter.Search.OnCommit = (sender, text) =>
+            currentQuery.ValueChanged += v =>
             {
-                lastQuery = Filter.Search.Text;
-                updateSets();
+                queryChangedDebounce?.Cancel();
+
+                if (string.IsNullOrEmpty(v))
+                    Scheduler.AddOnce(updateSearch);
+                else
+                {
+                    BeatmapSets = null;
+                    ResultAmounts = null;
+
+                    queryChangedDebounce = Scheduler.AddDelayed(updateSearch, 500);
+                }
             };
 
+            currentQuery.BindTo(Filter.Search.Current);
+
             Filter.Tabs.Current.ValueChanged += sortCriteria =>
             {
                 if (Header.Tabs.Current.Value != DirectTab.Search && sortCriteria != (DirectSortCriteria)Header.Tabs.Current.Value)
@@ -157,7 +169,7 @@ namespace osu.Game.Overlays
 
         private void updateResultCounts()
         {
-            resultCountsContainer.FadeTo(ResultAmounts == null ? 0f : 1f, 200, EasingTypes.Out);
+            resultCountsContainer.FadeTo(ResultAmounts == null ? 0f : 1f, 200, EasingTypes.OutQuint);
             if (ResultAmounts == null) return;
 
             resultCountsText.Text = pluralize("Artist", ResultAmounts.Artists) + ", " +
@@ -177,9 +189,15 @@ namespace osu.Game.Overlays
         }
 
         private GetBeatmapSetsRequest getSetsRequest;
-        private string lastQuery = string.Empty;
+
+        private readonly Bindable<string> currentQuery = new Bindable<string>();
+
+        private ScheduledDelegate queryChangedDebounce;
+
         private void updateSearch()
         {
+            queryChangedDebounce?.Cancel();
+
             if (!IsLoaded) return;
 
             BeatmapSets = null;
@@ -211,10 +229,9 @@ namespace osu.Game.Overlays
                     tags.AddRange(s.Metadata.Tags.Split(' '));
                 }
 
-                ResultAmounts = new ResultCounts(distinctCount(artists),
-                                                 distinctCount(songs),
-                                                 distinctCount(tags));
+                ResultAmounts = new ResultCounts(distinctCount(artists), distinctCount(songs), distinctCount(tags));
             };
+
             api.Queue(getSetsRequest);
         }