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

Pressing the ENTER key in a TextField should not move the focus #2252

Closed
rgl opened this issue Dec 13, 2022 · 8 comments · Fixed by #3195
Closed

Pressing the ENTER key in a TextField should not move the focus #2252

rgl opened this issue Dec 13, 2022 · 8 comments · Fixed by #3195
Labels

Comments

@rgl
Copy link

rgl commented Dec 13, 2022

Describe the bug

Pressing the ENTER key in a TextField should not move the focus away from the TextField.

To Reproduce

Steps to reproduce the behavior:

  1. Use the example at https://github.com/gui-cs/Terminal.Gui#sample-usage-in-c
  2. Press the ENTER key (in the username TextField, which should be focused by default).
  3. See that the cursor/focus is not in the TextField anymore

Expected behavior

I expected the focus to remain in the TextField where I've pressed the ENTER key.

@BDisp
Copy link
Collaborator

BDisp commented Dec 13, 2022

That is the expected behavior if the button is set as default. If you set IsDefault = false, then the Textfield wouldn't loss the focus.

@rgl
Copy link
Author

rgl commented Dec 13, 2022

With IsDefault = false, pressing the ENTER key in the TextField would still trigger the default button action? If not, I do not want to do that, as that looses the ability to trigger the default button action.

IMHO, the expected behavior should be like Windows Forms control, where it does not loose focus.

@BDisp
Copy link
Collaborator

BDisp commented Dec 13, 2022

With IsDefault = false, pressing the ENTER key in the TextField would still trigger the default button action?

No, if it's false then will not trigger the button action and the TextField maintain the focus.

@rgl
Copy link
Author

rgl commented Dec 13, 2022

Ah, so I do not want to do that, as that looses the ability to trigger the default button action. IMHO, it should behave be like Windows Forms, where it does not loose focus. That is a much better user experience than having the focus unexpectedly bouncing to the button.

@BDisp
Copy link
Collaborator

BDisp commented Dec 13, 2022

When the button is default it will get the focus but it can focus again the previous focused view with some change to the button action, It's a suggestion to do that feature :-)

@BDisp
Copy link
Collaborator

BDisp commented Dec 13, 2022

In Button.cs it's only need do change like this:

		///<inheritdoc/>
		public override bool ProcessColdKey (KeyEvent kb)
		{
			if (!Enabled) {
				return false;
			}

			var focused = SuperView?.MostFocused;
			var res = ExecuteColdKey (kb);
			focused?.SetFocus ();
			return res;
		}

@tig tig added the bug label Dec 31, 2022
@tig
Copy link
Collaborator

tig commented Jan 19, 2024

I believe this is addressed. Closing. Reopen if you disagree.

@tig tig closed this as completed Jan 19, 2024
@rgl
Copy link
Author

rgl commented Jan 19, 2024

@tig why do you believe its addressed? was there a commit about this?

BDisp added a commit to BDisp/Terminal.Gui that referenced this issue Jan 20, 2024
@BDisp BDisp reopened this Jan 20, 2024
@tig tig closed this as completed in #3195 Jan 20, 2024
tig pushed a commit that referenced this issue Jan 20, 2024
…e focus (#3195)

* Fixes #2252. Pressing the ENTER key in a TextField should not move the focus

* Update xml doc.

* Tested on WSL-Ubuntu-20.04
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants