~eliasnaur/gio

28c206fc78c76b1481fc3ed4c28ce3562ce424ba — Elias Naur 10 months ago 2993ba1
io/router: try all handlers if a key don't match the focus ancestor tree

When a key.InputOp is focused, a key.Event is matched to it and its ancestors.
If there is no focus, every handler is matched.
This change always matches to every handler, after checking the focus and
its ancestors.

Signed-off-by: Elias Naur <mail@eliasnaur.com>
2 files changed, 8 insertions(+), 2 deletions(-)

M io/router/key_test.go
M io/router/router.go
M io/router/key_test.go => io/router/key_test.go +2 -2
@@ 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)
}


M io/router/router.go => io/router/router.go +6 -0
@@ 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--
		}