Skip to content

Commit

Permalink
bindings: Add capability to unregister user defined raw escape sequence
Browse files Browse the repository at this point in the history
  • Loading branch information
JoeKar committed Oct 15, 2023
1 parent 07ab1c2 commit c04e8fa
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 4 deletions.
12 changes: 8 additions & 4 deletions internal/action/bindings.go
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -258,9 +261,6 @@ func TryBindKey(k, v string, overwrite bool) (bool, error) {
return false, errors.New("Error reading bindings.json: " + err.Error())
}

// Convert possible received string of raw escape sequence
k = strings.ReplaceAll(k, "\\x1b", "\x1b")

key, err := findEvent(k)
if err != nil {
return false, err
Expand Down Expand Up @@ -325,6 +325,10 @@ func UnbindKey(k string) error {
}
}

if strings.HasPrefix(k, "\x1b") {
screen.Screen.UnregisterRawSeq(k)

Check failure on line 329 in internal/action/bindings.go

View workflow job for this annotation

GitHub Actions / test (1.19.x, ubuntu-latest)

screen.Screen.UnregisterRawSeq undefined (type tcell.Screen has no field or method UnregisterRawSeq)

Check failure on line 329 in internal/action/bindings.go

View workflow job for this annotation

GitHub Actions / test (1.19.x, macos-latest)

screen.Screen.UnregisterRawSeq undefined (type tcell.Screen has no field or method UnregisterRawSeq)
}

defaults := DefaultBindings("buffer")
if a, ok := defaults[k]; ok {
BindKey(k, a, Binder["buffer"])
Expand Down
6 changes: 6 additions & 0 deletions internal/action/command.go
Original file line number Diff line number Diff line change
Expand Up @@ -660,6 +660,9 @@ func (h *BufPane) BindCmd(args []string) {
return
}

// Convert possible received string of raw escape sequence
args[0] = strings.ReplaceAll(args[0], "\\x1b", "\x1b")

_, err := TryBindKey(args[0], args[1], true)
if err != nil {
InfoBar.Error(err)
Expand All @@ -673,6 +676,9 @@ func (h *BufPane) UnbindCmd(args []string) {
return
}

// Convert possible received string of raw escape sequence
args[0] = strings.ReplaceAll(args[0], "\\x1b", "\x1b")

err := UnbindKey(args[0])
if err != nil {
InfoBar.Error(err)
Expand Down

0 comments on commit c04e8fa

Please sign in to comment.