fix(debugger): open the Debug window on Console, and on the view last picked (#3316)

The Debug window switched to Console only when it was open while the session was starting; a window opened later mounted on Threads & Variables, and a remount forgot the user's choice. It now opens on Console until a view is picked, then on the view last picked; a breakpoint or exception still brings Threads & Variables forward.
This commit is contained in:
l0ng-ai
2026-11-14 15:46:03 +08:00
committed by GitHub
parent e41cf32a94
commit f2b85eca4c
2 changed files with 22 additions and 2 deletions
@@ -228,6 +228,20 @@ describe("debug tool window", () => {
expect(console.getAttribute("aria-selected")).toBe("true");
});
it("opens on Console for a running session, and on the view last picked when shown again", () => {
useDebug.setState({ sessions: { 1: { ...session, status: "running" } }, active: 1 });
const first = render(<DebugToolWindow />);
expect(screen.getByRole("tab", { name: "Console" }).getAttribute("aria-selected")).toBe("true");
fireEvent.click(screen.getByRole("tab", { name: "Threads & Variables" }));
first.unmount();
const again = render(<DebugToolWindow />);
expect(screen.getByRole("tab", { name: "Threads & Variables" }).getAttribute("aria-selected")).toBe("true");
fireEvent.click(screen.getByRole("tab", { name: "Console" }));
again.unmount();
render(<DebugToolWindow />);
expect(screen.getByRole("tab", { name: "Console" }).getAttribute("aria-selected")).toBe("true");
});
it("renders session tabs, views, frames and typed variables", async () => {
useDebug.setState({ sessions: { 1: session }, active: 1 });
render(
+8 -2
View File
@@ -103,6 +103,9 @@ function MoreActions() {
type Tab = "variables" | "console" | "memory";
/** The view the user last picked; the tool window opens on it again (Console until one is picked). */
let chosenTab: Tab = "console";
function statusText(s: DebugSession): string {
if (s.status === "terminated") return s.exitCode != null ? `Finished · exit code ${s.exitCode}` : "Finished";
if (s.status === "starting") return "Starting…";
@@ -149,7 +152,7 @@ export function DebugToolWindow() {
session: number | undefined;
status: DebugSession["status"] | undefined;
tab: Tab;
}>({ session: undefined, status: undefined, tab: "variables" });
}>({ session: undefined, status: undefined, tab: chosenTab });
if (active && (view.session !== active.startedAt || view.status !== active.status))
setView({
session: active.startedAt,
@@ -232,7 +235,10 @@ export function DebugToolWindow() {
aria-selected={tab === id}
aria-controls={`debug-panel-${id}`}
className={clsx(styles.tab, tab === id && styles.tabActive)}
onClick={() => setView({ session: active.startedAt, status: active.status, tab: id })}
onClick={() => {
chosenTab = id;
setView({ session: active.startedAt, status: active.status, tab: id });
}}
>
{tx(label)}
</button>