From 5b5772968c5c115d909ba0da3ee65646f8d93cb2 Mon Sep 17 00:00:00 2001 From: Chris Waldon Date: Wed, 26 Oct 2022 15:41:28 -0400 Subject: [PATCH] richtext: fix interactive span aliasing This commit fixes a subtle bug that only permitted a single interactive span per richtext.TextStyle. The loop iterating the spans copied the spans as a loop variable and assigned an important piece of tracking metadata only on the copy. This resulted in all interactive spans thinking they were the first, and thus the final span was the only active one. Signed-off-by: Chris Waldon --- richtext/richtext.go | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/richtext/richtext.go b/richtext/richtext.go index c74bcb7..d28e95e 100644 --- a/richtext/richtext.go +++ b/richtext/richtext.go @@ -201,7 +201,8 @@ func (t TextStyle) Layout(gtx layout.Context) layout.Dimensions { // OPT(dh): it'd be nice to avoid this allocation styles := make([]styledtext.SpanStyle, len(t.Styles)) numInteractive := 0 - for i, st := range t.Styles { + for i := range t.Styles { + st := &t.Styles[i] if st.Interactive { st.interactiveIdx = numInteractive numInteractive++ -- 2.45.2