mirror of
https://github.com/jesseduffield/lazygit.git
synced 2026-09-10 07:36:27 -04:00
Add a helper for recognizing printable keys
Two places test for "a character the user typed" by hand, and a third one is about to be needed. Give the test a name. Co-authored-by: Claude Opus 5 (1M context) <noreply@anthropic.com>
This commit is contained in:
parent
c840013ca3
commit
b2a684bec1
|
|
@ -78,7 +78,7 @@ func SimpleEditor(v *View, key Key) bool {
|
|||
v.TextArea.GoToEndOfLine()
|
||||
case key.Equals(NewKeyStrMod("y", ModCtrl)):
|
||||
v.TextArea.Yank()
|
||||
case key.Str() != "" && key.Mod() == 0:
|
||||
case key.IsPrintable():
|
||||
v.TextArea.TypeCharacter(key.Str())
|
||||
default:
|
||||
return false
|
||||
|
|
|
|||
|
|
@ -2097,7 +2097,7 @@ func (g *Gui) matchView(v *View, kb *keybinding) bool {
|
|||
if v == nil {
|
||||
return false
|
||||
}
|
||||
if v.Editable && kb.key.Str() != "" && kb.key.Mod() == 0 {
|
||||
if v.Editable && kb.key.IsPrintable() {
|
||||
return false
|
||||
}
|
||||
if kb.viewName != v.name {
|
||||
|
|
|
|||
|
|
@ -61,6 +61,12 @@ func (k Key) IsSet() bool {
|
|||
return k.keyName != 0
|
||||
}
|
||||
|
||||
// IsPrintable reports whether the key stands for a character that can be typed
|
||||
// into a text field.
|
||||
func (k Key) IsPrintable() bool {
|
||||
return k.keyName == KeyName(tcell.KeyRune) && k.str != "" && k.mod == ModNone
|
||||
}
|
||||
|
||||
func (k Key) Equals(otherKey Key) bool {
|
||||
return k.keyName == otherKey.keyName && k.str == otherKey.str && k.mod == otherKey.mod
|
||||
}
|
||||
|
|
|
|||
16
pkg/gocui/key_test.go
Normal file
16
pkg/gocui/key_test.go
Normal file
|
|
@ -0,0 +1,16 @@
|
|||
package gocui
|
||||
|
||||
import (
|
||||
"testing"
|
||||
|
||||
"github.com/stretchr/testify/assert"
|
||||
)
|
||||
|
||||
func TestKeyIsPrintable(t *testing.T) {
|
||||
assert.True(t, NewKeyRune('x').IsPrintable())
|
||||
assert.True(t, NewKeyRune('界').IsPrintable())
|
||||
assert.True(t, NewKeyRune(' ').IsPrintable())
|
||||
assert.False(t, NewKeyStrMod("x", ModCtrl).IsPrintable())
|
||||
assert.False(t, NewKeyName(KeyEnter).IsPrintable())
|
||||
assert.False(t, Key{}.IsPrintable())
|
||||
}
|
||||
Loading…
Reference in a new issue