From f01f2cf860fd9d4e5ac300a9fd40e00b1e080644 Mon Sep 17 00:00:00 2001 From: l0ng-ai <24760907+l0ng-ai@users.noreply.github.com> Date: Wed, 18 Nov 2026 18:51:44 +0800 Subject: [PATCH] fix(debugger): Breakpoints dialog selects on click and keeps typed conditions A single click on a breakpoint jumped to its source and closed the dialog, and a condition typed and confirmed with Enter (Done) was lost, as only leaving the field saved it. A click now selects the breakpoint (double-click or Enter goes to the source), and the shown breakpoint's typed fields are saved when the dialog closes or another breakpoint is shown, for method and field breakpoints too; unchanged fields are not written again. Fixes #4150 --- .../__tests__/breakpointsDialog.test.tsx | 57 ++++++++++++++++ src/features/debugger/ui/Overlays.tsx | 68 ++++++++++++++++--- 2 files changed, 115 insertions(+), 10 deletions(-) create mode 100644 src/features/debugger/__tests__/breakpointsDialog.test.tsx diff --git a/src/features/debugger/__tests__/breakpointsDialog.test.tsx b/src/features/debugger/__tests__/breakpointsDialog.test.tsx new file mode 100644 index 0000000000..9f6bf44f80 --- /dev/null +++ b/src/features/debugger/__tests__/breakpointsDialog.test.tsx @@ -0,0 +1,57 @@ +import { afterEach, beforeEach, describe, expect, it, vi } from "vitest"; +import { act, cleanup, fireEvent, render, screen, within } from "@testing-library/react"; +import { provideEditorService } from "@/workbench/contributions"; +import { addBreakpoint, useBreakpoints } from "../breakpoints/store"; +import { DebuggerOverlays } from "../ui/Overlays"; +import { useOverlays } from "../ui/popoverStore"; + +const openFile = vi.fn(async () => undefined); +provideEditorService({ openFile } as never); + +const path = "/p/main.py"; + +describe("the Breakpoints dialog", () => { + beforeEach(() => { + openFile.mockClear(); + useBreakpoints.setState({ byFile: {}, status: {}, muted: false }); + const first = addBreakpoint(path, 2, { condition: "value == 2" }); + addBreakpoint(path, 6); + useOverlays.setState({ breakpoints: { id: first.id } } as never); + }); + afterEach(() => { + cleanup(); + act(() => useOverlays.setState({ breakpoints: null } as never)); + }); + + const dialog = () => screen.getByRole("dialog", { name: "Breakpoints" }); + const row = (name: string) => within(within(dialog()).getByLabelText("All breakpoints")).getByText(name); + const condition = () => within(dialog()).getByLabelText("Condition") as HTMLInputElement; + /** A row's mouse click as the list sees it: mousedown selects, click (with its count) activates. */ + const clickRow = (name: string, detail: number) => { + fireEvent.mouseDown(row(name), { button: 0 }); + fireEvent.click(row(name), { detail }); + }; + const breakpointAt = (line: number) => useBreakpoints.getState().byFile[path]!.find((b) => b.line === line)!; + + it("selects a breakpoint on click and goes to its source on double-click", () => { + render(); + clickRow("main.py:7", 1); + expect(openFile).not.toHaveBeenCalled(); + // Its details show beside the list. + expect(within(dialog()).getAllByText("main.py:7")).toHaveLength(2); + clickRow("main.py:3", 2); + expect(openFile).toHaveBeenCalledWith(path, { selection: { line: 2, col: 0 } }); + }); + + it("saves the condition being typed when the dialog closes or another breakpoint is shown", () => { + render(); + fireEvent.change(condition(), { target: { value: "value == 1" } }); + fireEvent.click(within(dialog()).getByRole("button", { name: "Done" })); + expect(breakpointAt(2).condition).toBe("value == 1"); + + act(() => useOverlays.setState({ breakpoints: { id: breakpointAt(2).id } } as never)); + fireEvent.change(condition(), { target: { value: "value == 3" } }); + clickRow("main.py:7", 1); + expect(breakpointAt(2).condition).toBe("value == 3"); + }); +}); diff --git a/src/features/debugger/ui/Overlays.tsx b/src/features/debugger/ui/Overlays.tsx index 8056febe31..8408d899a0 100644 --- a/src/features/debugger/ui/Overlays.tsx +++ b/src/features/debugger/ui/Overlays.tsx @@ -179,12 +179,19 @@ function BreakpointFields({ const commitText = () => { const d = draft.current; const cond = d.condition.trim() || null; - if (cond) pushHistory("condition", cond); - updateBreakpoint(path, bp.id, { + const changes = { condition: cond, hitCondition: d.hitCondition.trim() || null, logMessage: d.logEval ? d.logMessage.trim() || null : null, - }); + }; + if ( + changes.condition === (bp.condition ?? null) && + changes.hitCondition === (bp.hitCondition ?? null) && + changes.logMessage === (bp.logMessage ?? null) + ) + return; + if (cond) pushHistory("condition", cond); + updateBreakpoint(path, bp.id, changes); }; useEffect(() => { if (!commitRef) return; @@ -396,9 +403,13 @@ function BreakpointsDialog() { }, [byFile, methods, fields]); const items = rows.filter((r) => r.type !== "section"); const [selected, setSelected] = useState(null); + // The shown breakpoint's typed fields, saved before it is closed or another one is shown: + // Enter on Done and a click on a row don't blur them. + const commitRef = useRef<(() => void) | null>(null); const open = !!state; const current = items.find((r) => r.key === (selected ?? state?.id)) ?? items[0]; const close = () => { + commitRef.current?.(); setSelected(null); useOverlays.setState({ breakpoints: null }); }; @@ -448,8 +459,14 @@ function BreakpointsDialog() { isSection={(r) => r.type === "section"} renderSection={(r) =>
{r.type === "section" ? r.label : ""}
} activeIndex={current ? rows.indexOf(current) : -1} - onActiveChange={(i) => setSelected(rows[i]?.key ?? null)} - onActivate={(r) => goTo(r)} + onActiveChange={(i) => { + commitRef.current?.(); + setSelected(rows[i]?.key ?? null); + }} + // A click selects; double-click or Enter goes to the source. + onActivate={(r, _i, e) => { + if (e.type === "keydown" || e.detail > 1) goTo(r); + }} aria-label="All breakpoints" className={styles.bpList} empty={ @@ -522,9 +539,9 @@ function BreakpointsDialog() {
{current?.type === "line" ? ( - goTo(current)} /> + goTo(current)} commitRef={commitRef} /> ) : current?.type === "special" ? ( - goTo(current)} /> + goTo(current)} commitRef={commitRef} /> ) : null}
@@ -579,7 +596,15 @@ function ExceptionBreakpoints({ open }: { open: boolean }) { ); } -function BreakpointDetail({ row, onGo }: { row: BpRow; onGo: () => void }) { +function BreakpointDetail({ + row, + onGo, + commitRef, +}: { + row: BpRow; + onGo: () => void; + commitRef: MutableRefObject<(() => void) | null>; +}) { const { path, bp } = row; const st = useBreakpoints((s) => s.status[bp.id]); return ( @@ -597,7 +622,7 @@ function BreakpointDetail({ row, onGo }: { row: BpRow; onGo: () => void }) { {st &&
{st.verified ? tx("Verified") : (st.message ?? "Not verified")}
} - + updateBreakpoint(path, bp.id, { temporary })} @@ -607,11 +632,34 @@ function BreakpointDetail({ row, onGo }: { row: BpRow; onGo: () => void }) { ); } -function SpecialDetail({ bp, onGo }: { bp: SpecialBreakpoint; onGo: () => void }) { +function SpecialDetail({ + bp, + onGo, + commitRef, +}: { + bp: SpecialBreakpoint; + onGo: () => void; + commitRef: MutableRefObject<(() => void) | null>; +}) { const st = useSpecialBreakpoints((s) => s.status[bp.id]); const [name, setName] = useState(bp.kind === "method" ? bp.name : bp.label); const [condition, setCondition] = useState(bp.condition ?? ""); const [hitCondition, setHitCondition] = useState(bp.hitCondition ?? ""); + const draft = useRef({ name, condition, hitCondition }); + useEffect(() => { + draft.current = { name, condition, hitCondition }; + commitRef.current = () => { + const d = draft.current; + updateSpecial(bp.id, { + name: d.name.trim(), + condition: d.condition.trim() || null, + hitCondition: d.hitCondition.trim() || null, + }); + }; + return () => { + commitRef.current = null; + }; + }); return (