mirror of
https://github.com/Maks1mS/bubbles.git
synced 2024-12-23 14:22:58 +03:00
fix(key): Unbound keys should be disabled
* fix condition for #188 This is a fix of https://github.com/charmbracelet/bubbles/pull/188 Unbound keys has nil keys and they are not Enabled
This commit is contained in:
parent
746ec595c3
commit
e49b5573bc
@ -106,7 +106,7 @@ func (b Binding) Help() Help {
|
||||
// keybindings won't be activated and won't show up in help. Keybindings are
|
||||
// enabled by default.
|
||||
func (b Binding) Enabled() bool {
|
||||
return !b.disabled || b.keys == nil
|
||||
return !b.disabled && b.keys != nil
|
||||
}
|
||||
|
||||
// SetEnabled enables or disables the keybinding.
|
||||
|
26
key/key_test.go
Normal file
26
key/key_test.go
Normal file
@ -0,0 +1,26 @@
|
||||
package key
|
||||
|
||||
import (
|
||||
"testing"
|
||||
)
|
||||
|
||||
func TestBinding_Enabled(t *testing.T) {
|
||||
binding := NewBinding(
|
||||
WithKeys("k", "up"),
|
||||
WithHelp("↑/k", "move up"),
|
||||
)
|
||||
if !binding.Enabled() {
|
||||
t.Errorf("expected key to be Enabled")
|
||||
}
|
||||
|
||||
binding.SetEnabled(false)
|
||||
if binding.Enabled() {
|
||||
t.Errorf("expected key not to be Enabled")
|
||||
}
|
||||
|
||||
binding.SetEnabled(true)
|
||||
binding.Unbind()
|
||||
if binding.Enabled() {
|
||||
t.Errorf("expected key not to be Enabled")
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user