From 69fd3f4d4b64d950efeb282d6140472db28deff8 Mon Sep 17 00:00:00 2001 From: Larry Clapp Date: Wed, 30 Jul 2025 09:09:29 -0400 Subject: [PATCH] focusableInThis: Return first focusable widget, not last WidgetBase.focusableInThis() says it "returns the first Focusable element within this widget". It calls WidgetWalkDown. WidgetWalkDown calls the given function and stops walking the current branch of the tree if the function returns false. But then it keeps going with other branches of the tree. Which means if there are multiple focusable child widgets, focusableInThis seems to return the last Focusable widget. Instead, abort the walk if the first focusable widget has been found. --- core/widgetevents.go | 3 +++ 1 file changed, 3 insertions(+) diff --git a/core/widgetevents.go b/core/widgetevents.go index ef5947f7fc..45d52ce995 100644 --- a/core/widgetevents.go +++ b/core/widgetevents.go @@ -574,6 +574,9 @@ func (wb *WidgetBase) SetFocus() { func (wb *WidgetBase) focusableInThis() Widget { var foc Widget wb.WidgetWalkDown(func(cw Widget, cwb *WidgetBase) bool { + if foc != nil { + return tree.Break + } if !cwb.AbilityIs(abilities.Focusable) { return tree.Continue }