fix(editor): preserve SQL selection when executing from toolbar

This commit is contained in:
二丫讲梵 authored and GitHub committed 2026-08-30 03:05:43 +08:00
1 parent 22775f3639
commit d5f4eadf7a
6 files changed
+69 -6

No files matched your search

@@ -4,6 +4,7 @@ import { createQueryEditorExecutionViewportOwnership, isQueryEditorPositionVisib
const queryEditorSource = readFileSync(new URL("../../../components/editor/QueryEditor.vue", import.meta.url), "utf8");
const contentAreaSource = readFileSync(new URL("../../../components/layout/ContentArea.vue", import.meta.url), "utf8");
const editorToolbarSource = readFileSync(new URL("../../../components/layout/EditorToolbar.vue", import.meta.url), "utf8");
const appSource = readFileSync(new URL("../../../App.vue", import.meta.url), "utf8");
const sqlExecutionSource = readFileSync(new URL("../../../composables/useSqlExecution.ts", import.meta.url), "utf8");
const queryStoreSource = readFileSync(new URL("../../../stores/queryStore.ts", import.meta.url), "utf8");
@@ -50,6 +51,21 @@ describe("QueryEditor execution routing", () => {
expect(executeModeBranch).toBeGreaterThan(selectionBranch);
});
it("captures the toolbar selection before the click event can change focus", () => {
expect(queryEditorSource).toContain("function captureExecutionSnapshot(): SqlExecutionSnapshot | undefined");
expect(queryEditorSource).toContain("return sqlExecutionSnapshotFromView(currentView);");
expect(contentAreaSource).toContain("function captureQueryEditorExecutionSnapshot()");
expect(contentAreaSource).toContain("queryEditorRef.value?.captureExecutionSnapshot();");
expect(appSource).toContain("const pendingToolbarExecutionSnapshot = ref<SqlExecutionSnapshot>();");
expect(appSource).toContain("pendingToolbarExecutionSnapshot.value = contentAreaRef.value?.captureQueryEditorExecutionSnapshot?.();");
expect(appSource).toContain('if (source === "pointer")');
expect(appSource).toContain("pendingToolbarExecutionSnapshot.value = undefined;");
expect(appSource).toContain("void tryExecute(snapshot);");
expect(appSource).toContain('@execute-pointer-down="captureActiveEditorExecutionSnapshot()"');
expect(appSource).toContain('@execute="requestActiveEditorExecute($event)"');
expect(editorToolbarSource).toContain("function onExecutePointerDown(event: MouseEvent)");
});
it("uses the opt-in blank-line fallback and otherwise reports the missing cursor statement", () => {
expect(queryEditorSource).toContain("executeAllOnBlankLine: settingsStore.editorSettings.executeAllOnBlankLine");
expect(queryEditorSource).toContain('toast(t("editor.noExecutableStatementAtCursor"), 3000)');
@@ -51,7 +51,7 @@ describe("QueryEditor auto focus wiring", () => {
describe("QueryEditor toolbar focus", () => {
it("does not move focus from the editor when clicking execute", () => {
expect(editorToolbarSource).toMatch(/:disabled="activeTab\.isCancelling[\s\S]*?@mousedown\.prevent[\s\S]*?@click="activeTab\.isExecuting \? emit\('cancel'\) : emit\('execute'\)"/);
expect(editorToolbarSource).toMatch(/:disabled="activeTab\.isCancelling[\s\S]*?@mousedown\.prevent="onExecutePointerDown"[\s\S]*?@click="onExecuteClick"/);
expect(queryEditorSource).toMatch(/function requestExecute\([\s\S]*?const currentView = view\.value;[\s\S]*?currentView\.focus\(\);[\s\S]*?requestExecuteFromView\(currentView/);
});
});