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

Cannot override Text KeyMap #73

Closed
guigui64 opened this issue Dec 18, 2023 · 2 comments
Closed

Cannot override Text KeyMap #73

guigui64 opened this issue Dec 18, 2023 · 2 comments
Labels
bug Something isn't working

Comments

@guigui64
Copy link

Describe the bug
WithKeyMap does not seem to have any effect on the Text field.

To Reproduce
Steps to reproduce the behavior:

textField := huh.NewText().
	Title("...").
	Value(&message).
	WithKeyMap(&huh.KeyMap{
		Text: huh.TextKeyMap{
			Next:    key.NewBinding(key.WithKeys("ctrl+enter"), key.WithHelp("ctrl+enter", "next")),
			Prev:    key.NewBinding(key.WithKeys("shift+tab"), key.WithHelp("shift+tab", "back")),
			NewLine: key.NewBinding(key.WithKeys("enter", "ctrl+j"), key.WithHelp("enter / ctrl+j", "new line")),
			Editor:  key.NewBinding(key.WithKeys("ctrl+e"), key.WithHelp("ctrl+e", "open editor")),
		},
	})

form := huh.NewForm(
	huh.NewGroup(
		textField,
	),
)

Help text at the end of the field does not reflect the new KeyMap and the default keymap still applies.

Expected behavior
Next and NewLine should have been overriden.

@meowgorithm meowgorithm added the bug Something isn't working label Dec 19, 2023
@meowgorithm
Copy link
Member

Hi! Thanks for the report. For now, you can change the keymap on the form to achieve the same effect:

textField := huh.NewText().
	Title("...").
	Value(&message)

form := huh.NewForm(
	huh.NewGroup(
		textField,
	),
).WithKeyMap(&huh.KeyMap{
	Text: huh.TextKeyMap{
		Next:    key.NewBinding(key.WithKeys("ctrl+enter"), key.WithHelp("ctrl+enter", "next")),
		Prev:    key.NewBinding(key.WithKeys("shift+tab"), key.WithHelp("shift+tab", "back")),
		NewLine: key.NewBinding(key.WithKeys("enter", "ctrl+j"), key.WithHelp("enter / ctrl+j", "new line")),
		Editor:  key.NewBinding(key.WithKeys("ctrl+e"), key.WithHelp("ctrl+e", "open editor")),
	},
})

@caarlos0
Copy link
Member

closing per @meowgorithm response

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

3 participants