From 03ed6be82d3bbf46271c6465ad5e3554de523b2e Mon Sep 17 00:00:00 2001 From: l0ng-ai <24760907+l0ng-ai@users.noreply.github.com> Date: Tue, 27 Oct 2026 22:39:43 +0800 Subject: [PATCH] fix(ui): Activating a tool window focuses its content, not its first button --- src/workbench/toolwindows/ToolWindows.tsx | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/src/workbench/toolwindows/ToolWindows.tsx b/src/workbench/toolwindows/ToolWindows.tsx index 5f20c9df..63c84079 100644 --- a/src/workbench/toolwindows/ToolWindows.tsx +++ b/src/workbench/toolwindows/ToolWindows.tsx @@ -573,8 +573,13 @@ function ToolWindowView({ tw, hidden }: { tw: ToolWindowContribution; hidden: bo const root = ref.current; if (!root) return; const body = root.querySelector("[data-toolwindow-body]"); - const target = - body?.querySelector("[data-autofocus]") ?? body?.querySelector(FOCUSABLE) ?? root; + // Like IDEA, activation focuses the content (a field, list or tree), never a button or + // link: a scripted focus on one draws its focus ring (an empty view's "New…" link). + const content = [...(body?.querySelectorAll(FOCUSABLE) ?? [])].find( + (el) => !el.matches('button, a[href], [role="button"], [role="link"]'), + ); + if (body && !content && !body.hasAttribute("tabindex")) body.tabIndex = -1; + const target = body?.querySelector("[data-autofocus]") ?? content ?? body ?? root; target.focus({ preventScroll: true }); }); return () => cancelAnimationFrame(raf);