Implement backtab for tcell widgets

This commit is contained in:
Matthew Coleman 2024-01-27 17:34:33 -05:00
parent e4ccfa3102
commit 120b02117f
7 changed files with 9 additions and 4 deletions

View File

@ -1939,7 +1939,7 @@ func TestMouse(t *testing.T) {
),
Right(
PlaceWidget(fakewidget.New(widgetapi.Options{WantKeyboard: widgetapi.KeyScopeFocused})),
KeyFocusPrevious(keyboard.KeyTab),
KeyFocusPrevious(keyboard.KeyBacktab),
),
),
)
@ -1949,7 +1949,7 @@ func TestMouse(t *testing.T) {
return c, nil
},
events: []terminalapi.Event{
&terminalapi.Keyboard{Key: keyboard.KeyTab},
&terminalapi.Keyboard{Key: keyboard.KeyBacktab},
},
want: func(size image.Point) *faketerm.Terminal {
ft := faketerm.MustNew(size)
@ -1966,7 +1966,7 @@ func TestMouse(t *testing.T) {
&widgetapi.Meta{Focused: true},
widgetapi.Options{WantKeyboard: widgetapi.KeyScopeFocused},
&fakewidget.Event{
Ev: &terminalapi.Keyboard{Key: keyboard.KeyTab},
Ev: &terminalapi.Keyboard{Key: keyboard.KeyBacktab},
Meta: &widgetapi.EventMeta{Focused: true},
},
)

View File

@ -529,7 +529,7 @@ func TestFocusTrackerNextAndPrevious(t *testing.T) {
const (
keyNext keyboard.Key = keyboard.KeyTab
keyPrevious keyboard.Key = '~'
keyPrevious keyboard.Key = keyboard.KeyBacktab
)
tests := []struct {

View File

@ -65,6 +65,7 @@ var buttonNames = map[Key]string{
KeyCtrlG: "KeyCtrlG",
KeyBackspace: "KeyBackspace",
KeyTab: "KeyTab",
KeyBacktab: "KeyBacktab",
KeyCtrlJ: "KeyCtrlJ",
KeyCtrlK: "KeyCtrlK",
KeyCtrlL: "KeyCtrlL",
@ -130,6 +131,7 @@ const (
KeyCtrlG
KeyBackspace
KeyTab
KeyBacktab
KeyCtrlJ
KeyCtrlK
KeyCtrlL

View File

@ -77,6 +77,7 @@ var tcellToTd = map[tcell.Key]keyboard.Key{
tcell.KeyCtrlZ: keyboard.KeyCtrlZ,
tcell.KeyBackspace: keyboard.KeyBackspace,
tcell.KeyTab: keyboard.KeyTab,
tcell.KeyBacktab: keyboard.KeyBacktab,
tcell.KeyEscape: keyboard.KeyEsc,
tcell.KeyCtrlBackslash: keyboard.KeyCtrlBackslash,
tcell.KeyCtrlRightSq: keyboard.KeyCtrlRsqBracket,

View File

@ -218,6 +218,7 @@ func TestKeyboardKeys(t *testing.T) {
{key: tcell.KeyBackspace, want: keyboard.KeyCtrlH},
{key: tcell.KeyCtrlH, want: keyboard.KeyBackspace},
{key: tcell.KeyTab, want: keyboard.KeyTab},
{key: tcell.KeyBacktab, want: keyboard.KeyBacktab},
{key: tcell.KeyTab, want: keyboard.KeyCtrlI},
{key: tcell.KeyCtrlI, want: keyboard.KeyTab},
{key: tcell.KeyCtrlJ, want: keyboard.KeyCtrlJ},

Binary file not shown.

View File

@ -167,6 +167,7 @@ func newForm(cancel context.CancelFunc) (*form, error) {
func formLayout(c *container.Container, f *form) error {
return c.Update("root",
container.KeyFocusNext(keyboard.KeyTab),
container.KeyFocusPrevious(keyboard.KeyBacktab),
container.KeyFocusGroupsNext(keyboard.KeyArrowDown, 1),
container.KeyFocusGroupsPrevious(keyboard.KeyArrowUp, 1),
container.KeyFocusGroupsNext(keyboard.KeyArrowRight, 2),