1
0
mirror of https://github.com/ppy/osu.git synced 2024-12-25 23:55:35 +08:00
osu-lazer/osu.Game/Graphics/UserInterface/SearchTextBox.cs

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

76 lines
2.2 KiB
C#
Raw Normal View History

// Copyright (c) ppy Pty Ltd <contact@ppy.sh>. Licensed under the MIT Licence.
// See the LICENCE file in the repository root for full licence text.
2018-04-13 17:19:50 +08:00
2022-06-17 15:37:17 +08:00
#nullable disable
2019-07-16 13:55:41 +08:00
using osu.Framework.Input;
2018-10-02 11:02:47 +08:00
using osu.Framework.Input.Events;
using osu.Game.Resources.Localisation.Web;
2018-11-20 15:51:59 +08:00
using osuTK.Input;
2018-04-13 17:19:50 +08:00
namespace osu.Game.Graphics.UserInterface
{
2017-02-19 16:59:22 +08:00
public partial class SearchTextBox : FocusedTextBox
{
protected virtual bool AllowCommit => false;
2018-04-13 17:19:50 +08:00
public SearchTextBox()
{
Height = 35;
PlaceholderText = HomeStrings.SearchPlaceholder;
}
2018-04-13 17:19:50 +08:00
2021-09-16 17:26:12 +08:00
public override bool OnPressed(KeyBindingPressEvent<PlatformAction> e)
2019-07-16 13:55:41 +08:00
{
2021-09-16 17:26:12 +08:00
switch (e.Action)
{
2021-07-20 13:23:34 +08:00
case PlatformAction.MoveBackwardLine:
case PlatformAction.MoveForwardLine:
2019-12-31 01:38:22 +08:00
// Shift+delete is handled via PlatformAction on macOS. this is not so useful in the context of a SearchTextBox
// as we do not allow arrow key navigation in the first place (ie. the caret should always be at the end of text)
// Avoid handling it here to allow other components to potentially consume the shortcut.
2021-07-20 13:23:34 +08:00
case PlatformAction.DeleteForwardChar:
return false;
}
2021-09-16 17:26:12 +08:00
return base.OnPressed(e);
2019-07-16 13:55:41 +08:00
}
2018-10-02 11:02:47 +08:00
protected override bool OnKeyDown(KeyDownEvent e)
{
if (!e.ControlPressed && !e.ShiftPressed)
{
2018-10-02 11:02:47 +08:00
switch (e.Key)
{
case Key.Left:
case Key.Right:
case Key.Up:
case Key.Down:
return false;
}
}
2018-04-13 17:19:50 +08:00
if (!AllowCommit)
{
2018-10-02 11:02:47 +08:00
switch (e.Key)
{
case Key.KeypadEnter:
case Key.Enter:
return false;
}
}
2018-04-13 17:19:50 +08:00
if (e.ShiftPressed)
{
2018-10-02 11:02:47 +08:00
switch (e.Key)
{
case Key.Delete:
return false;
}
}
2018-04-13 17:19:50 +08:00
2018-10-02 11:02:47 +08:00
return base.OnKeyDown(e);
}
}
2018-01-05 19:21:19 +08:00
}