From e3ef98dda382665c7fa6c959c5428e7b1899e72e Mon Sep 17 00:00:00 2001 From: Elias Naur Date: Fri, 26 May 2023 17:03:49 -0600 Subject: [PATCH] Revert "io/router: try all handlers if a key don't match the focus ancestor tree" This reverts commit 28c206fc78c76b1481fc3ed4c28ce3562ce424ba. The commit introduced counter-intuitive behaviour as demonstrated by #503. In the meantime, topmost handlers now receive all unhandled key.Events[0], which should cover the use-cases that motivated the original commit. [0] https://gioui.org/commit/0dba85f52e5131c03d903c84355fb90cdb978811 Fixes: https://todo.sr.ht/~eliasnaur/gio/503 Signed-off-by: Elias Naur --- io/router/key_test.go | 4 ++-- io/router/router.go | 6 ------ 2 files changed, 2 insertions(+), 8 deletions(-) diff --git a/io/router/key_test.go b/io/router/key_test.go index b8dc9e92..2e39a3db 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, and then every handler. + // containing the focused element. 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, B) + assertKeyEvent(t, r2.Events(&handlers[1]), false) assertKeyEvent(t, r2.Events(&handlers[0]), false, A) } diff --git a/io/router/router.go b/io/router/router.go index 3f4a40aa..c7fad915 100644 --- a/io/router/router.go +++ b/io/router/router.go @@ -221,12 +221,6 @@ 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-- } -- 2.38.5