Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

TextBox should only handle keyboard input when focused #1471

Merged
merged 2 commits into from Mar 22, 2018
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
23 changes: 9 additions & 14 deletions osu.Framework/Graphics/UserInterface/TextBox.cs
Expand Up @@ -31,6 +31,8 @@ public class TextBox : TabbableContainer, IHasCurrentValue<string>
protected Drawable Caret;
protected Container TextContainer;

public override bool HandleKeyboardInput => HasFocus;

/// <summary>
/// Padding to be used within the TextContainer. Requires special handling due to the sideways scrolling of text content.
/// </summary>
Expand Down Expand Up @@ -576,9 +578,6 @@ protected bool HandlePendingText(InputState state)

protected override bool OnKeyDown(InputState state, KeyDownEventArgs args)
{
if (!HasFocus)
return false;

if (textInput?.ImeActive == true) return true;

if (args.Key <= Key.F35)
Expand All @@ -602,19 +601,15 @@ protected override bool OnKeyDown(InputState state, KeyDownEventArgs args)

case Key.KeypadEnter:
case Key.Enter:
if (HasFocus)
{
if (ReleaseFocusOnCommit)
GetContainingInputManager().ChangeFocus(null);

Background.Colour = ReleaseFocusOnCommit ? BackgroundUnfocused : BackgroundFocused;
Background.ClearTransforms();
Background.FlashColour(BackgroundCommit, 400);
if (ReleaseFocusOnCommit)
GetContainingInputManager().ChangeFocus(null);

audio.Sample.Get(@"Keyboard/key-confirm")?.Play();
OnCommit?.Invoke(this, true);
}
Background.Colour = ReleaseFocusOnCommit ? BackgroundUnfocused : BackgroundFocused;
Background.ClearTransforms();
Background.FlashColour(BackgroundCommit, 400);

audio.Sample.Get(@"Keyboard/key-confirm")?.Play();
OnCommit?.Invoke(this, true);
return true;
}

Expand Down