mirror of
https://git.sr.ht/~eliasnaur/gio
synced 2026-07-06 01:45:36 +00:00
io/router: search all key handlers when there is no focus
Fixes: https://todo.sr.ht/~eliasnaur/gio/434 Signed-off-by: Elias Naur <mail@eliasnaur.com>
This commit is contained in:
@@ -335,7 +335,7 @@ func TestKeyRouting(t *testing.T) {
|
|||||||
key.InputOp{Tag: &handlers[2], Keys: "A"}.Add(ops)
|
key.InputOp{Tag: &handlers[2], Keys: "A"}.Add(ops)
|
||||||
cl1.Pop()
|
cl1.Pop()
|
||||||
cl2 := rect.Push(ops)
|
cl2 := rect.Push(ops)
|
||||||
key.InputOp{Tag: &handlers[3], Keys: "B"}.Add(ops)
|
key.InputOp{Tag: &handlers[3]}.Add(ops)
|
||||||
key.InputOp{Tag: &handlers[4], Keys: "A"}.Add(ops)
|
key.InputOp{Tag: &handlers[4], Keys: "A"}.Add(ops)
|
||||||
cl2.Pop()
|
cl2.Pop()
|
||||||
call := macro.Stop()
|
call := macro.Stop()
|
||||||
@@ -349,15 +349,15 @@ func TestKeyRouting(t *testing.T) {
|
|||||||
// With no focus, the events should traverse the final branch of the hit tree
|
// With no focus, the events should traverse the final branch of the hit tree
|
||||||
// searching for handlers.
|
// searching for handlers.
|
||||||
assertKeyEvent(t, r.Events(&handlers[4]), false, A)
|
assertKeyEvent(t, r.Events(&handlers[4]), false, A)
|
||||||
assertKeyEvent(t, r.Events(&handlers[3]), false, B)
|
assertKeyEvent(t, r.Events(&handlers[3]), false)
|
||||||
assertKeyEvent(t, r.Events(&handlers[2]), false)
|
assertKeyEvent(t, r.Events(&handlers[2]), false)
|
||||||
assertKeyEvent(t, r.Events(&handlers[1]), false)
|
assertKeyEvent(t, r.Events(&handlers[1]), false, B)
|
||||||
assertKeyEvent(t, r.Events(&handlers[0]), false)
|
assertKeyEvent(t, r.Events(&handlers[0]), false)
|
||||||
|
|
||||||
r2 := new(Router)
|
r2 := new(Router)
|
||||||
|
|
||||||
call.Add(ops)
|
call.Add(ops)
|
||||||
key.FocusOp{Tag: &handlers[2]}.Add(ops)
|
key.FocusOp{Tag: &handlers[3]}.Add(ops)
|
||||||
r2.Frame(ops)
|
r2.Frame(ops)
|
||||||
|
|
||||||
r2.Queue(A, B)
|
r2.Queue(A, B)
|
||||||
@@ -365,10 +365,10 @@ func TestKeyRouting(t *testing.T) {
|
|||||||
// With focus, the events should traverse the branch of the hit tree
|
// With focus, the events should traverse the branch of the hit tree
|
||||||
// containing the focused element.
|
// containing the focused element.
|
||||||
assertKeyEvent(t, r2.Events(&handlers[4]), false)
|
assertKeyEvent(t, r2.Events(&handlers[4]), false)
|
||||||
assertKeyEvent(t, r2.Events(&handlers[3]), false)
|
assertKeyEvent(t, r2.Events(&handlers[3]), true)
|
||||||
assertKeyEvent(t, r2.Events(&handlers[2]), true, A)
|
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)
|
assertKeyEvent(t, r2.Events(&handlers[0]), false, A)
|
||||||
}
|
}
|
||||||
|
|
||||||
func assertKeyEvent(t *testing.T, events []event.Event, expectedFocus bool, expectedInputs ...event.Event) {
|
func assertKeyEvent(t *testing.T, events []event.Event, expectedFocus bool, expectedInputs ...event.Event) {
|
||||||
|
|||||||
+8
-3
@@ -191,7 +191,8 @@ func (q *Router) queueKeyEvent(e key.Event) {
|
|||||||
}
|
}
|
||||||
pq := &q.pointer.queue
|
pq := &q.pointer.queue
|
||||||
idx := len(pq.hitTree) - 1
|
idx := len(pq.hitTree) - 1
|
||||||
if f != nil {
|
focused := f != nil
|
||||||
|
if focused {
|
||||||
// If there is a focused tag, traverse its ancestry through the
|
// If there is a focused tag, traverse its ancestry through the
|
||||||
// hit tree to search for handlers.
|
// hit tree to search for handlers.
|
||||||
for ; pq.hitTree[idx].ktag != f; idx-- {
|
for ; pq.hitTree[idx].ktag != f; idx-- {
|
||||||
@@ -199,11 +200,15 @@ func (q *Router) queueKeyEvent(e key.Event) {
|
|||||||
}
|
}
|
||||||
for idx != -1 {
|
for idx != -1 {
|
||||||
n := &pq.hitTree[idx]
|
n := &pq.hitTree[idx]
|
||||||
idx = n.next
|
if focused {
|
||||||
|
idx = n.next
|
||||||
|
} else {
|
||||||
|
idx--
|
||||||
|
}
|
||||||
if n.ktag == nil {
|
if n.ktag == nil {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
if n.ktag != nil && kq.Accepts(n.ktag, e) {
|
if kq.Accepts(n.ktag, e) {
|
||||||
q.handlers.Add(n.ktag, e)
|
q.handlers.Add(n.ktag, e)
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user