mirror of
https://github.com/zyedidia/micro.git
synced 2026-02-06 15:10:27 +09:00
Merge pull request #2959 from JoeKar/fix/raw-esc-sequence
bindings: Allow raw escape sequence to be bound with `bind`
This commit is contained in:
@@ -88,6 +88,10 @@ func BindKey(k, v string, bind func(e Event, a string)) {
|
||||
return
|
||||
}
|
||||
|
||||
if strings.HasPrefix(k, "\x1b") {
|
||||
screen.Screen.RegisterRawSeq(k)
|
||||
}
|
||||
|
||||
bind(event, v)
|
||||
|
||||
// switch e := event.(type) {
|
||||
@@ -153,7 +157,6 @@ modSearch:
|
||||
k = k[5:]
|
||||
modifiers |= tcell.ModShift
|
||||
case strings.HasPrefix(k, "\x1b"):
|
||||
screen.Screen.RegisterRawSeq(k)
|
||||
return RawEvent{
|
||||
esc: k,
|
||||
}, true
|
||||
@@ -331,6 +334,10 @@ func UnbindKey(k string) error {
|
||||
}
|
||||
}
|
||||
|
||||
if strings.HasPrefix(k, "\x1b") {
|
||||
screen.Screen.UnregisterRawSeq(k)
|
||||
}
|
||||
|
||||
defaults := DefaultBindings("buffer")
|
||||
if a, ok := defaults[k]; ok {
|
||||
BindKey(k, a, Binder["buffer"])
|
||||
|
||||
@@ -638,6 +638,11 @@ func (h *BufPane) ShowCmd(args []string) {
|
||||
InfoBar.Message(option)
|
||||
}
|
||||
|
||||
func parseKeyArg(arg string) string {
|
||||
// If this is a raw escape sequence, convert it to its raw byte form
|
||||
return strings.ReplaceAll(arg, "\\x1b", "\x1b")
|
||||
}
|
||||
|
||||
// ShowKeyCmd displays the action that a key is bound to
|
||||
func (h *BufPane) ShowKeyCmd(args []string) {
|
||||
if len(args) < 1 {
|
||||
@@ -645,7 +650,7 @@ func (h *BufPane) ShowKeyCmd(args []string) {
|
||||
return
|
||||
}
|
||||
|
||||
event, err := findEvent(args[0])
|
||||
event, err := findEvent(parseKeyArg(args[0]))
|
||||
if err != nil {
|
||||
InfoBar.Error(err)
|
||||
return
|
||||
@@ -664,7 +669,7 @@ func (h *BufPane) BindCmd(args []string) {
|
||||
return
|
||||
}
|
||||
|
||||
_, err := TryBindKey(args[0], args[1], true)
|
||||
_, err := TryBindKey(parseKeyArg(args[0]), args[1], true)
|
||||
if err != nil {
|
||||
InfoBar.Error(err)
|
||||
}
|
||||
@@ -677,7 +682,7 @@ func (h *BufPane) UnbindCmd(args []string) {
|
||||
return
|
||||
}
|
||||
|
||||
err := UnbindKey(args[0])
|
||||
err := UnbindKey(parseKeyArg(args[0]))
|
||||
if err != nil {
|
||||
InfoBar.Error(err)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user