diff --git a/key.go b/key.go index 7f05b87..e2415a9 100644 --- a/key.go +++ b/key.go @@ -198,6 +198,7 @@ const ( KeyPgUp KeyPgDown KeyDelete + KeySpace KeyCtrlUp KeyCtrlDown KeyCtrlRight @@ -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", @@ -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}), diff --git a/key_test.go b/key_test.go index b8ce47d..511ae75 100644 --- a/key_test.go +++ b/key_test.go @@ -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) } @@ -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) } })