diff --git a/apps/desktop/src/components/editor/QueryEditor.vue b/apps/desktop/src/components/editor/QueryEditor.vue
index f7b3fa699..99b1c5eb7 100644
--- a/apps/desktop/src/components/editor/QueryEditor.vue
+++ b/apps/desktop/src/components/editor/QueryEditor.vue
@@ -623,6 +623,7 @@ function emitExecutionRequest(source: SqlExecutionOverride, openInNewResultTab =
function requestExecute(options: RequestExecuteOptions = {}) {
const currentView = view.value;
if (!currentView) return false;
+ currentView.focus();
return requestExecuteFromView(currentView, currentView.state.selection.main.head, options);
}
diff --git a/apps/desktop/src/components/layout/EditorToolbar.vue b/apps/desktop/src/components/layout/EditorToolbar.vue
index 9fc804490..269cb482c 100644
--- a/apps/desktop/src/components/layout/EditorToolbar.vue
+++ b/apps/desktop/src/components/layout/EditorToolbar.vue
@@ -229,6 +229,7 @@ async function changeCatalog(selectedCatalog: string) {
class="h-6 w-6"
:class="executeButtonClass"
:disabled="activeTab.isCancelling || activeTab.isExplaining || (!activeTab.isExecuting && !executableSql.trim())"
+ @mousedown.prevent
@click="activeTab.isExecuting ? emit('cancel') : emit('execute')"
>
diff --git a/apps/desktop/src/lib/__tests__/editor/queryEditorFocus.spec.ts b/apps/desktop/src/lib/__tests__/editor/queryEditorFocus.spec.ts
index 59ff8fe96..fb64dc9a6 100644
--- a/apps/desktop/src/lib/__tests__/editor/queryEditorFocus.spec.ts
+++ b/apps/desktop/src/lib/__tests__/editor/queryEditorFocus.spec.ts
@@ -4,6 +4,7 @@ import { focusEditorView, type EditorViewLike } from "@/lib/editor/queryEditorFo
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");
function createMockView(overrides: Partial = {}): EditorViewLike {
return {
@@ -47,3 +48,10 @@ describe("QueryEditor auto focus wiring", () => {
expect(contentAreaSource).toMatch(/ {
+ 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(queryEditorSource).toMatch(/function requestExecute\([\s\S]*?const currentView = view\.value;[\s\S]*?currentView\.focus\(\);[\s\S]*?requestExecuteFromView\(currentView/);
+ });
+});