Add additional context to key binding set

This commit is contained in:
Drew DeVault 2019-03-21 16:35:35 -04:00
parent 10dd23f05d
commit 79b459ecb0
1 changed files with 14 additions and 4 deletions

View File

@ -20,7 +20,14 @@ type Binding struct {
Input []KeyStroke Input []KeyStroke
} }
type KeyBindings []*Binding type KeyBindings struct {
bindings []*Binding
// If false, disable global keybindings in this context
Globals bool
// Which key opens the ex line (default is :)
ExKey KeyStroke
}
const ( const (
BINDING_FOUND = iota BINDING_FOUND = iota
@ -31,12 +38,15 @@ const (
type BindingSearchResult int type BindingSearchResult int
func NewKeyBindings() *KeyBindings { func NewKeyBindings() *KeyBindings {
return &KeyBindings{} return &KeyBindings{
ExKey: KeyStroke{tcell.KeyRune, ':'},
Globals: true,
}
} }
func (bindings *KeyBindings) Add(binding *Binding) { func (bindings *KeyBindings) Add(binding *Binding) {
// TODO: Search for conflicts? // TODO: Search for conflicts?
*bindings = append(*bindings, binding) bindings.bindings = append(bindings.bindings, binding)
} }
func (bindings *KeyBindings) GetBinding( func (bindings *KeyBindings) GetBinding(
@ -45,7 +55,7 @@ func (bindings *KeyBindings) GetBinding(
incomplete := false incomplete := false
// TODO: This could probably be a sorted list to speed things up // TODO: This could probably be a sorted list to speed things up
// TODO: Deal with bindings that share a prefix // TODO: Deal with bindings that share a prefix
for _, binding := range *bindings { for _, binding := range bindings.bindings {
if len(binding.Input) < len(input) { if len(binding.Input) < len(input) {
continue continue
} }