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

change(keys): spacebar sends a KeySpace #315

Merged
merged 2 commits into from May 13, 2022
Merged

Conversation

meowgorithm
Copy link
Member

This update reverts the hasty #311 and reimplements @bashbunni's excellent #289.

After further pondering we've decided it makes the most sense to make the following small change to the message produced by the spacebar after all:

// Before
Key{Type: KeyRunes, Runes: []rune{' '}}

// After!
Key{Type: KeySpace, Runes: []rune{' '}}

Note that the String() method will still return " " for backwards compatibility.

The reasoning for this change is that binding things to the spacebar is common, but doing so in a "safe" manner is currently a bit cumbersome. Consider the following:

// For comparison
if msg.Type == tea.KeyEnter {

// Similar and straightforward
if msg.Type == tea.KeySpace {

// Urgh
if msg.Type == tea.KeyRunes && msg.String() == " " {

// Urghhhhh
if msg.Type == tea.KeyRunes && len(msg.Runes) == 1 && msg.Runes[0] == ' ' {

If course most of the time people simply:

if msg.String() == " " {

So all-in-all this effectively is a minor change.

Also note that after this is released we'll need to address the issue in charmbracelet/bubbles#144 accordingly.

@meowgorithm meowgorithm merged commit d301ee0 into master May 13, 2022
@meowgorithm meowgorithm deleted the hello-again-keyspace branch May 13, 2022 17:24
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

1 participant