Terminal.Gui icon indicating copy to clipboard operation
Terminal.Gui copied to clipboard

`TextField` prevents default `Button` from working in some cases

Open tig opened this issue 1 year ago • 7 comments

This test shows that TextField is preventing ENTER from invoking Accept on the default button.

[Fact]
public void Enter_Prevents_Default_Button_Accept ()
{
    var superView = new Window ();
    var tf = new TextField ();
    var button = new Button ()
    {
        IsDefault = true,
    };

    superView.Add (tf, button);

    var buttonAccept = 0;
    button.Accept += ButtonAccept;

    var textFieldAccept = 0;
    tf.Accept += TextFieldAccept;

    tf.SetFocus ();
    Assert.True (tf.HasFocus);

    superView.NewKeyDownEvent (Key.Enter);
    Assert.Equal (1, textFieldAccept);
    Assert.Equal (0, buttonAccept);

    button.SetFocus();
    superView.NewKeyDownEvent (Key.Enter);
    Assert.Equal (1, textFieldAccept);
    Assert.Equal (1, buttonAccept);

    return;

    void TextFieldAccept (object sender, CancelEventArgs e) { textFieldAccept++; }
    void ButtonAccept (object sender, CancelEventArgs e) { buttonAccept++; }
}

We def want TextField to support firing Accept on Key.Enter. However, not in every case.

I use this in CharMap for example.

But in the video below, the default button should be invoked when one of the TF's has focus.

Background

Do you think that the hotkey PR, also broken the Accept event not being raising on a default button when the Enter key is pressed?

Seems fine to me?

Note that if the TextFields have focus, it doesn't work because TextField has registered ENTER.

nuTWrak 1

Originally posted by @tig in https://github.com/gui-cs/Terminal.Gui/issues/3565#issuecomment-2192523217

tig avatar Jun 26 '24 20:06 tig