diff --git a/apps/desktop/src/components/editor/QueryEditor.vue b/apps/desktop/src/components/editor/QueryEditor.vue index e595e13e1..1e4c177c7 100644 --- a/apps/desktop/src/components/editor/QueryEditor.vue +++ b/apps/desktop/src/components/editor/QueryEditor.vue @@ -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([ diff --git a/apps/desktop/src/lib/__tests__/editor/queryEditorExecution.spec.ts b/apps/desktop/src/lib/__tests__/editor/queryEditorExecution.spec.ts new file mode 100644 index 000000000..8d8b1af91 --- /dev/null +++ b/apps/desktop/src/lib/__tests__/editor/queryEditorExecution.spec.ts @@ -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); + }); +});