From 303b819539916ce37940be9a1edcbcf3cb954c1c Mon Sep 17 00:00:00 2001 From: Elias Naur Date: Wed, 10 Nov 2021 13:24:17 +0100 Subject: [PATCH] io/router: don't panic for nil op.Ops arguements to Router.Frame Fixes gio#306 Signed-off-by: Elias Naur --- io/router/key_test.go | 5 +++++ io/router/router.go | 8 ++++++-- 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/io/router/key_test.go b/io/router/key_test.go index 7824014b..be50ac8a 100644 --- a/io/router/key_test.go +++ b/io/router/key_test.go @@ -220,6 +220,11 @@ func TestKeyFocusedInvisible(t *testing.T) { } +func TestNoOps(t *testing.T) { + r := new(Router) + r.Frame(nil) +} + func assertKeyEvent(t *testing.T, events []event.Event, expected bool, expectedInputs ...event.Event) { t.Helper() var evtFocus int diff --git a/io/router/router.go b/io/router/router.go index 3f217d74..03ba608e 100644 --- a/io/router/router.go +++ b/io/router/router.go @@ -68,13 +68,17 @@ func (q *Router) Events(k event.Tag) []event.Event { // Frame replaces the declared handlers from the supplied // operation list. The text input state, wakeup time and whether // there are active profile handlers is also saved. -func (q *Router) Frame(ops *op.Ops) { +func (q *Router) Frame(frame *op.Ops) { q.handlers.Clear() q.wakeup = false for k := range q.profHandlers { delete(q.profHandlers, k) } - q.reader.Reset(&ops.Internal) + var ops *ops.Ops + if frame != nil { + ops = &frame.Internal + } + q.reader.Reset(ops) q.collect() q.pointer.queue.Frame(&q.handlers)