io/router: move focus on tab and shift+tab

Fixes: https://todo.sr.ht/~eliasnaur/gio/195
Signed-off-by: Elias Naur <mail@eliasnaur.com>
This commit is contained in:
Elias Naur
2022-02-24 15:06:29 +01:00
parent cd2ade0583
commit 2e9df04a7b
2 changed files with 86 additions and 26 deletions
+23 -2
View File
@@ -145,7 +145,7 @@ func TestKeyRemoveFocus(t *testing.T) {
assertKeyEventUnexpected(t, r.Events(&handlers[0]))
assertKeyEventUnexpected(t, r.Events(&handlers[1]))
assertFocus(t, r, nil)
assertKeyboard(t, r, TextInputKeep)
assertKeyboard(t, r, TextInputClose)
ops.Reset()
@@ -216,7 +216,7 @@ func TestKeyFocusedInvisible(t *testing.T) {
assertKeyEvent(t, r.Events(&handlers[0]), false)
assertKeyEventUnexpected(t, r.Events(&handlers[1]))
assertFocus(t, r, nil)
assertKeyboard(t, r, TextInputKeep)
assertKeyboard(t, r, TextInputClose)
}
@@ -225,6 +225,27 @@ func TestNoOps(t *testing.T) {
r.Frame(nil)
}
func TestTabFocus(t *testing.T) {
handlers := make([]int, 3)
ops := new(op.Ops)
r := new(Router)
for i := range handlers {
key.InputOp{Tag: &handlers[i]}.Add(ops)
}
r.Frame(ops)
tab := func(mod key.Modifiers) {
r.Queue(
key.Event{Name: key.NameTab, State: key.Press, Modifiers: mod},
key.Event{Name: key.NameTab, State: key.Release, Modifiers: mod},
)
}
tab(0)
tab(key.ModShift)
assertFocus(t, r, &handlers[2])
}
func assertKeyEvent(t *testing.T, events []event.Event, expected bool, expectedInputs ...event.Event) {
t.Helper()
var evtFocus int