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
Show file tree
Hide file tree
Changes from all commits
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
10 changes: 10 additions & 0 deletions key.go
Expand Up @@ -198,6 +198,7 @@ const (
KeyPgUp
KeyPgDown
KeyDelete
KeySpace
KeyCtrlUp
KeyCtrlDown
KeyCtrlRight
Expand Down Expand Up @@ -274,6 +275,7 @@ var keyNames = map[KeyType]string{
KeyUp: "up",
KeyDown: "down",
KeyRight: "right",
KeySpace: " ", // for backwards compatibility
KeyLeft: "left",
KeyShiftTab: "shift+tab",
KeyHome: "home",
Expand Down Expand Up @@ -552,6 +554,14 @@ func readInputs(input io.Reader) ([]Msg, error) {
}, nil
}

// If it's a space, override the type with KeySpace (but still include the
// rune).
if runes[0] == ' ' {
return []Msg{
KeyMsg(Key{Type: KeySpace, Runes: runes}),
}, nil
}

// Welp, it's just a regular, ol' single rune.
return []Msg{
KeyMsg(Key{Type: KeyRunes, Runes: runes}),
Expand Down
10 changes: 3 additions & 7 deletions key_test.go
Expand Up @@ -8,9 +8,8 @@ import (
func TestKeyString(t *testing.T) {
t.Run("alt+space", func(t *testing.T) {
if got := KeyMsg(Key{
Type: KeyRunes,
Runes: []rune{' '},
Alt: true,
Type: KeySpace,
Alt: true,
}).String(); got != "alt+ " {
t.Fatalf(`expected a "alt+ ", got %q`, got)
}
Expand All @@ -36,10 +35,7 @@ func TestKeyString(t *testing.T) {

func TestKeyTypeString(t *testing.T) {
t.Run("space", func(t *testing.T) {
if got := KeyMsg(Key{
Type: KeyRunes,
Runes: []rune{' '},
}).String(); got != " " {
if got := KeySpace.String(); got != " " {
t.Fatalf(`expected a " ", got %q`, got)
}
})
Expand Down