From c224b3c972b1924d9dcdf3feb0385b7d4b7cdd92 Mon Sep 17 00:00:00 2001 From: zipg Date: Sat, 26 Sep 2026 01:32:04 +0800 Subject: [PATCH] fix(editor): keep batch column session across empty results --- .../useQueryEditorBatchSelection.spec.ts | 19 +++++++++++++++++-- .../editor/useQueryEditorBatchSelection.ts | 12 +++++++++++- 2 files changed, 28 insertions(+), 3 deletions(-) diff --git a/apps/desktop/src/components/editor/__tests__/useQueryEditorBatchSelection.spec.ts b/apps/desktop/src/components/editor/__tests__/useQueryEditorBatchSelection.spec.ts index 70d64f5af6..ec84a8cdd0 100644 --- a/apps/desktop/src/components/editor/__tests__/useQueryEditorBatchSelection.spec.ts +++ b/apps/desktop/src/components/editor/__tests__/useQueryEditorBatchSelection.spec.ts @@ -91,8 +91,23 @@ describe("QueryEditor batch selection ownership", () => { batch.toggleAllBatchColumnSelection(currentView, session.key); expect(next.selectedKeys.size).toBe(0); expect(next.completionOptions.size).toBe(0); - batch.prepareBatchColumnSelectionSession([], next.document, next.from, next.to); - expect(batch.expandedRendering).toBe(false); + }); + + it("keeps the checked fields when a sibling result carries no column candidates (dbx#9973)", () => { + const { batch, session, items, currentView, row } = createHarness(); + batch.toggleAllBatchColumnSelection(currentView, session.key); + // One completion request builds several result sets and only some of them + // carry column candidates. The empty one must not drop the session that the + // rendered checkbox rows still point at. + expect(batch.prepareBatchColumnSelectionSession([], session.document, session.from, session.to)).toBeNull(); + expect(batch.expandedRendering).toBe(true); + expect(batch.prepareBatchColumnSelectionSession(items, session.document, session.from, session.to)).toBe(session); + expect(session.selectedKeys).toEqual(new Set(session.candidates.map((candidate) => candidate.key))); + const { checkbox } = row(0); + expect(checkbox.checked).toBe(true); + checkbox.dispatchEvent(new PointerEvent("pointerdown", { button: 0, buttons: 1, isPrimary: true, pointerId: 5, bubbles: true })); + expect(session.selectedKeys.has(session.candidates[0].key)).toBe(false); + document.body.style.userSelect = ""; }); it("guards label clicks and applies checked fields together, never an individual row", () => { diff --git a/apps/desktop/src/components/editor/useQueryEditorBatchSelection.ts b/apps/desktop/src/components/editor/useQueryEditorBatchSelection.ts index 84497255a0..d515694248 100644 --- a/apps/desktop/src/components/editor/useQueryEditorBatchSelection.ts +++ b/apps/desktop/src/components/editor/useQueryEditorBatchSelection.ts @@ -254,7 +254,17 @@ export function useQueryEditorBatchSelection(options: QueryEditorBatchSelectionO function prepareBatchColumnSelectionSession(items: SqlCompletionItem[], document: string, from: number, to: number): BatchColumnSelectionSession | null { const selectableItems = items.filter((item) => item.type === "column" && item.batchSelectionMode && item.apply); if (selectableItems.length === 0) { - clearBatchColumnSelectionSession(); + // One completion request builds several result sets (the local pass plus + // the metadata pass) and only some of them carry column candidates. + // Clearing the stored session for such an empty sibling result left the + // checkbox rows rendered by the other result attached to a session that + // no longer existed, so clicking a checkbox did nothing. It also made the + // expanded-rendering flag flap false→true on every pass, reconfiguring + // CodeMirror's autocompletion compartment while a source was still + // pending; the recreated list stayed disabled (ArrowUp/Down ignored, then + // closed on the next caret move). Keep the session and only report "no + // batch selection" for this result (dbx#9973). The session is still + // dropped when the popup closes, on Escape and after an accepted row. return null; }