From 362d8eabae3b82dd7ea9a10ed076d49649ced219 Mon Sep 17 00:00:00 2001 From: Samantha Marshall Date: Mon, 2 Jan 2017 10:56:55 -0500 Subject: [PATCH 1/2] Adding functionality to unbind keys * adds new special-case keybinding to remove an existing default key binding. * hides the show/close help text in the status line when no key is assigned to "ToggleHelp" * updating documentation --- cmd/micro/bindings.go | 19 +++++++++++++------ cmd/micro/statusline.go | 9 ++++++--- runtime/help/keybindings.md | 6 ++++++ 3 files changed, 25 insertions(+), 9 deletions(-) diff --git a/cmd/micro/bindings.go b/cmd/micro/bindings.go index b537a9e1..3059ab3d 100644 --- a/cmd/micro/bindings.go +++ b/cmd/micro/bindings.go @@ -346,14 +346,21 @@ func BindKey(k, v string) { if v == "ToggleHelp" { helpBinding = k } - - actionNames := strings.Split(v, ",") - actions := make([]func(*View, bool) bool, 0, len(actionNames)) - for _, actionName := range actionNames { - actions = append(actions, findAction(actionName)) + if helpBinding == k && v != "ToggleHelp" { + helpBinding = "" } + + if v == "UnbindKey" { + delete(bindings, key) + } else { + actionNames := strings.Split(v, ",") + actions := make([]func(*View, bool) bool, 0, len(actionNames)) + for _, actionName := range actionNames { + actions = append(actions, findAction(actionName)) + } - bindings[key] = actions + bindings[key] = actions + } } // DefaultBindings returns a map containing micro's default keybindings diff --git a/cmd/micro/statusline.go b/cmd/micro/statusline.go index 7e646bfc..e339cf19 100644 --- a/cmd/micro/statusline.go +++ b/cmd/micro/statusline.go @@ -36,9 +36,12 @@ func (sline *Statusline) Display() { // Add the filetype file += " " + sline.view.Buf.FileType() - rightText := helpBinding + " for help " - if sline.view.Type == vtHelp { - rightText = helpBinding + " to close help " + rightText := "" + if len(helpBinding) > 0 { + rightText = helpBinding + " for help " + if sline.view.Type == vtHelp { + rightText = helpBinding + " to close help " + } } statusLineStyle := defStyle.Reverse(true) diff --git a/runtime/help/keybindings.md b/runtime/help/keybindings.md index 2dd494d0..ee9d1f11 100644 --- a/runtime/help/keybindings.md +++ b/runtime/help/keybindings.md @@ -115,6 +115,11 @@ and quit you can bind it like so: } ``` +# Unbinding keys + +It is also possible to disable any of the default key bindings by use of the +`UnbindKey` action in the user's `bindings.json` file. + # Bindable actions and bindable keys The list of default keybindings contains most of the possible actions and keys @@ -196,6 +201,7 @@ HSplit PreviousSplit ToggleMacro PlayMacro +UnbindKey ``` Here is the list of all possible keys you can bind: From 29502e7f417c8d292a6f102794030f160c90b057 Mon Sep 17 00:00:00 2001 From: Samantha Marshall Date: Mon, 2 Jan 2017 11:28:47 -0500 Subject: [PATCH 2/2] simplify the code around unbinding keys --- cmd/micro/bindings.go | 20 ++++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) diff --git a/cmd/micro/bindings.go b/cmd/micro/bindings.go index 3059ab3d..504efecc 100644 --- a/cmd/micro/bindings.go +++ b/cmd/micro/bindings.go @@ -350,17 +350,21 @@ func BindKey(k, v string) { helpBinding = "" } - if v == "UnbindKey" { + actionNames := strings.Split(v, ",") + if actionNames[0] == "UnbindKey" { delete(bindings, key) - } else { - actionNames := strings.Split(v, ",") - actions := make([]func(*View, bool) bool, 0, len(actionNames)) - for _, actionName := range actionNames { - actions = append(actions, findAction(actionName)) + if len(actionNames) == 1 { + actionNames = make([]string, 0, 0) + } else { + actionNames = append(actionNames[:0], actionNames[1:]...) } - - bindings[key] = actions } + actions := make([]func(*View, bool) bool, 0, len(actionNames)) + for _, actionName := range actionNames { + actions = append(actions, findAction(actionName)) + } + + bindings[key] = actions } // DefaultBindings returns a map containing micro's default keybindings