fix(editor): preserve focus after executing SQL

This commit is contained in:
zipg 2026-08-05 09:44:00 +08:00 committed by GitHub
parent 39fcaa15cb
commit 0dfc6b5cd8
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 10 additions and 0 deletions

View File

@ -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);
}

View File

@ -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')"
>
<Loader2 v-if="activeTab.isCancelling" class="h-3.5 w-3.5 animate-spin" />

View File

@ -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> = {}): EditorViewLike {
return {
@ -47,3 +48,10 @@ describe("QueryEditor auto focus wiring", () => {
expect(contentAreaSource).toMatch(/<QueryEditor[\s\S]*?\sauto-focus\s[\s\S]*?:model-value="activeTab\.sql"/);
});
});
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(queryEditorSource).toMatch(/function requestExecute\([\s\S]*?const currentView = view\.value;[\s\S]*?currentView\.focus\(\);[\s\S]*?requestExecuteFromView\(currentView/);
});
});