aboutsummaryrefslogtreecommitdiff
path: root/widgets
diff options
context:
space:
mode:
authorDrew DeVault <sir@cmpwn.com>2019-03-21 17:36:42 -0400
committerDrew DeVault <sir@cmpwn.com>2019-03-21 17:37:19 -0400
commitf5bf4a93243c62b5b30ed0f1d15c124739444c79 (patch)
tree68edf4ecdd4d979ead71f712860d2bd2101c53c2 /widgets
parent79b459ecb0da7759de617d164cb1cafc4a6be1c8 (diff)
Add context-specific keybindings
Diffstat (limited to 'widgets')
-rw-r--r--widgets/aerc.go46
1 files changed, 38 insertions, 8 deletions
diff --git a/widgets/aerc.go b/widgets/aerc.go
index af2d0df..8d456b1 100644
--- a/widgets/aerc.go
+++ b/widgets/aerc.go
@@ -94,6 +94,24 @@ func (aerc *Aerc) Draw(ctx *libui.Context) {
aerc.grid.Draw(ctx)
}
+func (aerc *Aerc) getBindings() *config.KeyBindings {
+ switch aerc.SelectedTab().(type) {
+ case *AccountView:
+ return aerc.conf.Bindings.MessageList
+ default:
+ return aerc.conf.Bindings.Global
+ }
+}
+
+func (aerc *Aerc) simulate(strokes []config.KeyStroke) {
+ aerc.pendingKeys = []config.KeyStroke{}
+ for _, stroke := range strokes {
+ simulated := tcell.NewEventKey(
+ stroke.Key, stroke.Rune, tcell.ModNone)
+ aerc.Event(simulated)
+ }
+}
+
func (aerc *Aerc) Event(event tcell.Event) bool {
if aerc.focused != nil {
return aerc.focused.Event(event)
@@ -105,18 +123,30 @@ func (aerc *Aerc) Event(event tcell.Event) bool {
Key: event.Key(),
Rune: event.Rune(),
})
- result, output := aerc.conf.Lbinds.GetBinding(aerc.pendingKeys)
+ bindings := aerc.getBindings()
+ incomplete := false
+ result, strokes := bindings.GetBinding(aerc.pendingKeys)
switch result {
case config.BINDING_FOUND:
- aerc.pendingKeys = []config.KeyStroke{}
- for _, stroke := range output {
- simulated := tcell.NewEventKey(
- stroke.Key, stroke.Rune, tcell.ModNone)
- aerc.Event(simulated)
- }
+ aerc.simulate(strokes)
+ return true
case config.BINDING_INCOMPLETE:
- return false
+ incomplete = true
case config.BINDING_NOT_FOUND:
+ }
+ if bindings.Globals {
+ result, strokes = aerc.conf.Bindings.Global.
+ GetBinding(aerc.pendingKeys)
+ switch result {
+ case config.BINDING_FOUND:
+ aerc.simulate(strokes)
+ return true
+ case config.BINDING_INCOMPLETE:
+ incomplete = true
+ case config.BINDING_NOT_FOUND:
+ }
+ }
+ if !incomplete {
aerc.pendingKeys = []config.KeyStroke{}
if event.Rune() == ':' {
aerc.BeginExCommand()