diff --git a/io/router/key_test.go b/io/router/key_test.go index 2e39a3db..b8dc9e92 100644 --- a/io/router/key_test.go +++ b/io/router/key_test.go @@ -363,11 +363,11 @@ func TestKeyRouting(t *testing.T) { r2.Queue(A, B) // With focus, the events should traverse the branch of the hit tree - // containing the focused element. + // containing the focused element, and then every handler. assertKeyEvent(t, r2.Events(&handlers[4]), false) assertKeyEvent(t, r2.Events(&handlers[3]), true) assertKeyEvent(t, r2.Events(&handlers[2]), false) - assertKeyEvent(t, r2.Events(&handlers[1]), false) + assertKeyEvent(t, r2.Events(&handlers[1]), false, B) assertKeyEvent(t, r2.Events(&handlers[0]), false, A) } diff --git a/io/router/router.go b/io/router/router.go index 48c2edcf..1feab04a 100644 --- a/io/router/router.go +++ b/io/router/router.go @@ -202,6 +202,12 @@ func (q *Router) queueKeyEvent(e key.Event) { n := &pq.hitTree[idx] if focused { idx = n.next + if idx == -1 { + // No handler found in focus ancestor tree. + // Try all handlers. + idx = len(pq.hitTree) - 1 + focused = false + } } else { idx-- }