Browse Source

Add UnifyEnterKeys option to interpret KPEnter as Enter

This option is enabled by default.
master v0.1.4
Trevor Slocum 2 years ago
parent
commit
475986e4fd
  1. 3
      CHANGELOG
  2. 13
      key.go

3
CHANGELOG

@ -1,3 +1,6 @@
0.1.4:
- Add UnifyEnterKeys option to interpret KPEnter as Enter (enabled by default)
0.1.3:
- Add Configuration.Set
- Return ErrInvalidKeyEvent when encoding or decoding fails

13
key.go

@ -16,6 +16,11 @@ const (
LabelShift = "shift"
)
// UnifyEnterKeys is a flag that determines whether or not KPEnter (keypad
// enter) key events are interpreted as Enter key events. When enabled, Ctrl+J
// key events are also interpreted as Enter key events.
var UnifyEnterKeys = true
// ErrInvalidKeyEvent is the error returned when encoding or decoding a key event fails.
var ErrInvalidKeyEvent = errors.New("invalid key event")
@ -139,7 +144,9 @@ DECODEPIECE:
k, ok := ctrlKeys[unicode.ToLower(ch)]
if ok {
key = k
if key < 0x80 {
if UnifyEnterKeys && key == ctrlKeys['j'] {
key = tcell.KeyEnter
} else if key < 0x80 {
ch = rune(key)
}
}
@ -167,7 +174,9 @@ func Encode(mod tcell.ModMask, key tcell.Key, ch rune) (string, error) {
}
if key != tcell.KeyRune {
if key < 0x80 {
if UnifyEnterKeys && key == ctrlKeys['j'] {
key = tcell.KeyEnter
} else if key < 0x80 {
ch = rune(key)
}
}

Loading…
Cancel
Save