fix(editor): respect configured SQL execution mode

This commit is contained in:
t8y2 2026-07-17 22:54:29 +08:00
parent 086e20f878
commit 990be3c329
2 changed files with 21 additions and 7 deletions

View File

@ -447,7 +447,6 @@ function handleTab(view: EditorViewType): boolean {
}
interface RequestExecuteOptions {
forceCurrent?: boolean;
ignoreSelection?: boolean;
}
@ -472,11 +471,6 @@ function requestExecuteFromView(currentView: EditorViewType, cursorPos: number,
const doc = currentView.state.doc.toString();
const candidates = buildExecutionCandidates(doc, cursorPos, props.databaseType);
if (candidates.length === 0) return false;
if (options.forceCurrent) {
const candidate = candidates.find((item) => item.kind === "cursor") ?? candidates[0];
emit("execute", candidate.sql);
return true;
}
if (!settingsStore.editorSettings.showExecutionTargetPicker || !hasMultipleExecutionTargets(doc, props.databaseType)) {
const preferredKind = settingsStore.editorSettings.executeMode === "current" ? "cursor" : "all";
const candidate = candidates.find((item) => item.kind === preferredKind) ?? candidates[0];
@ -1148,7 +1142,8 @@ function runKeymapExtension(codeMirrorKeymap: (typeof import("@codemirror/view")
const shortcuts = normalizeShortcutSettings(settingsStore.editorSettings.shortcuts);
const Prec = codeMirrorPrec;
const binding = (shortcut: string, run: (view: EditorViewType) => boolean) => (shortcut ? [{ key: shortcutToCodeMirrorKey(shortcut), preventDefault: true, run }] : []);
const executeBindings = props.hideExecutionControls ? [] : binding(shortcuts.executeSql, () => requestExecute({ forceCurrent: true }));
// Keep the shortcut on the shared path so selection, picker, and execute-mode behavior stay aligned with other execution entry points.
const executeBindings = props.hideExecutionControls ? [] : binding(shortcuts.executeSql, () => requestExecute());
return [
Prec?.high(
codeMirrorKeymap.of([

View File

@ -0,0 +1,19 @@
import { readFileSync } from "node:fs";
import { describe, expect, it } from "vitest";
const queryEditorSource = readFileSync(new URL("../../../components/editor/QueryEditor.vue", import.meta.url), "utf8");
describe("QueryEditor execution routing", () => {
it("routes the execution shortcut through the shared execution-mode contract", () => {
expect(queryEditorSource).toContain("binding(shortcuts.executeSql, () => requestExecute())");
expect(queryEditorSource).not.toContain("forceCurrent");
});
it("keeps selection priority and the configured current/all target choice", () => {
const selectionBranch = queryEditorSource.indexOf("if (!options.ignoreSelection && !selection.empty)");
const executeModeBranch = queryEditorSource.indexOf('settingsStore.editorSettings.executeMode === "current" ? "cursor" : "all"');
expect(selectionBranch).toBeGreaterThan(-1);
expect(executeModeBranch).toBeGreaterThan(selectionBranch);
});
});