mirror of
https://github.com/l0ng-ai/openidea.git
synced 2026-11-06 08:07:49 +00:00
fix(ui): Activating a tool window focuses its content, not its first button
This commit is contained in:
@@ -573,8 +573,13 @@ function ToolWindowView({ tw, hidden }: { tw: ToolWindowContribution; hidden: bo
|
||||
const root = ref.current;
|
||||
if (!root) return;
|
||||
const body = root.querySelector<HTMLElement>("[data-toolwindow-body]");
|
||||
const target =
|
||||
body?.querySelector<HTMLElement>("[data-autofocus]") ?? body?.querySelector<HTMLElement>(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<HTMLElement>(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<HTMLElement>("[data-autofocus]") ?? content ?? body ?? root;
|
||||
target.focus({ preventScroll: true });
|
||||
});
|
||||
return () => cancelAnimationFrame(raf);
|
||||
|
||||
Reference in New Issue
Block a user