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
This commit is contained in:
Samantha Marshall
2017-01-02 10:56:55 -05:00
parent a3c58e52fc
commit 362d8eabae
3 changed files with 25 additions and 9 deletions

View File

@@ -346,7 +346,13 @@ func BindKey(k, v string) {
if v == "ToggleHelp" { if v == "ToggleHelp" {
helpBinding = k helpBinding = k
} }
if helpBinding == k && v != "ToggleHelp" {
helpBinding = ""
}
if v == "UnbindKey" {
delete(bindings, key)
} else {
actionNames := strings.Split(v, ",") actionNames := strings.Split(v, ",")
actions := make([]func(*View, bool) bool, 0, len(actionNames)) actions := make([]func(*View, bool) bool, 0, len(actionNames))
for _, actionName := range actionNames { for _, actionName := range actionNames {
@@ -354,6 +360,7 @@ func BindKey(k, v string) {
} }
bindings[key] = actions bindings[key] = actions
}
} }
// DefaultBindings returns a map containing micro's default keybindings // DefaultBindings returns a map containing micro's default keybindings

View File

@@ -36,10 +36,13 @@ func (sline *Statusline) Display() {
// Add the filetype // Add the filetype
file += " " + sline.view.Buf.FileType() file += " " + sline.view.Buf.FileType()
rightText := helpBinding + " for help " rightText := ""
if len(helpBinding) > 0 {
rightText = helpBinding + " for help "
if sline.view.Type == vtHelp { if sline.view.Type == vtHelp {
rightText = helpBinding + " to close help " rightText = helpBinding + " to close help "
} }
}
statusLineStyle := defStyle.Reverse(true) statusLineStyle := defStyle.Reverse(true)
if style, ok := colorscheme["statusline"]; ok { if style, ok := colorscheme["statusline"]; ok {

View File

@@ -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 # Bindable actions and bindable keys
The list of default keybindings contains most of the possible actions and keys The list of default keybindings contains most of the possible actions and keys
@@ -196,6 +201,7 @@ HSplit
PreviousSplit PreviousSplit
ToggleMacro ToggleMacro
PlayMacro PlayMacro
UnbindKey
``` ```
Here is the list of all possible keys you can bind: Here is the list of all possible keys you can bind: