Skip to content

Commit

Permalink
Select first filtered channel on search box commit
Browse files Browse the repository at this point in the history
  • Loading branch information
bdach committed Oct 22, 2024
1 parent 826b35e commit 2ab68c6
Showing 1 changed file with 25 additions and 3 deletions.
28 changes: 25 additions & 3 deletions osu.Game/Overlays/Chat/ChannelList/ChannelList.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
using osu.Framework.Graphics.Shapes;
using osu.Framework.Graphics.UserInterface;
using osu.Framework.Localisation;
using osu.Framework.Testing;
using osu.Game.Graphics;
using osu.Game.Graphics.Containers;
using osu.Game.Graphics.Sprites;
Expand Down Expand Up @@ -71,11 +72,9 @@ private void load(OverlayColourProvider colourProvider)
RelativeSizeAxes = Axes.X,
AutoSizeAxes = Axes.Y,
Padding = new MarginPadding { Horizontal = 10, Top = 8 },
Child = searchTextBox = new BasicSearchTextBox
Child = searchTextBox = new ChannelSearchTextBox
{
RelativeSizeAxes = Axes.X,
Scale = new Vector2(0.8f),
Width = 1 / 0.8f,
}
},
announceChannelGroup = new ChannelGroup(ChatStrings.ChannelsListTitleANNOUNCE.ToUpper()),
Expand All @@ -88,6 +87,17 @@ private void load(OverlayColourProvider colourProvider)
};

searchTextBox.Current.BindValueChanged(_ => groupFlow.SearchTerm = searchTextBox.Current.Value, true);
searchTextBox.OnCommit += (_, _) =>
{
if (string.IsNullOrEmpty(searchTextBox.Current.Value))
return;

var firstMatchingItem = this.ChildrenOfType<ChannelListItem>().FirstOrDefault(item => item.MatchingFilter);
if (firstMatchingItem == null)
return;

OnRequestSelect?.Invoke(firstMatchingItem.Channel);
};

selector.OnRequestSelect += chan => OnRequestSelect?.Invoke(chan);
}
Expand Down Expand Up @@ -186,5 +196,17 @@ public ChannelGroup(LocalisableString label)
};
}
}

private partial class ChannelSearchTextBox : BasicSearchTextBox
{
protected override bool AllowCommit => true;

public ChannelSearchTextBox()
{
const float scale_factor = 0.8f;
Scale = new Vector2(scale_factor);
Width = 1 / scale_factor;
}
}
}
}

0 comments on commit 2ab68c6

Please sign in to comment.