From a414183ff051b13ef8e8d455dabebe400e4dde23 Mon Sep 17 00:00:00 2001 From: t8y2 <1156263951@qq.com> Date: Mon, 8 Jun 2026 23:08:50 +0800 Subject: [PATCH] fix(editor): scope SQL formatting to active tab --- apps/desktop/src/App.vue | 15 +++++++-------- .../desktop/src/components/layout/ContentArea.vue | 8 ++++---- 2 files changed, 11 insertions(+), 12 deletions(-) diff --git a/apps/desktop/src/App.vue b/apps/desktop/src/App.vue index da8fbff67d..acafdccb6c 100644 --- a/apps/desktop/src/App.vue +++ b/apps/desktop/src/App.vue @@ -125,7 +125,7 @@ const contentAreaRef = ref | null>(null); const selectedSql = ref(""); const cursorPos = ref(0); -const formatSqlRequestId = ref(0); +const formatSqlRequest = ref<{ id: number; tabId: string } | null>(null); const activeOutputView = ref<"result" | "summary" | "explain" | "chart">("result"); const newQueryContextSource = ref<"tab" | "sidebar">("tab"); const showSaveSqlDialog = ref(false); @@ -363,7 +363,10 @@ function analyzeHistoryWithAi(entry: HistoryEntry) { function formatActiveSql() { const tab = activeTab.value; if (!tab || tab.mode !== "query" || !tab.sql.trim()) return; - formatSqlRequestId.value++; + formatSqlRequest.value = { + id: (formatSqlRequest.value?.id ?? 0) + 1, + tabId: tab.id, + }; } function defaultSavedSqlName(title: string) { @@ -1103,7 +1106,7 @@ onUnmounted(() => { :active-connection="activeConnection" :executable-sql="executableSql" :active-output-view="activeOutputView" - :format-sql-request-id="formatSqlRequestId" + :format-sql-request="formatSqlRequest" :selected-sql="selectedSql" :cursor-pos="cursorPos" @update:active-output-view="activeOutputView = $event" @@ -1111,11 +1114,7 @@ onUnmounted(() => { @execute="tryExecute()" @cancel="cancelActiveExecution()" @explain="tryExplain()" - @editor-update=" - (v: string) => { - if (queryStore.activeTabId) queryStore.updateSql(queryStore.activeTabId, v); - } - " + @editor-update="(tabId: string, v: string) => queryStore.updateSql(tabId, v)" @editor-selection-change="(v: string) => (selectedSql = v)" @editor-cursor-change="(p: number) => (cursorPos = p)" @format-error="toast(t('toolbar.formatSqlFailed'))" diff --git a/apps/desktop/src/components/layout/ContentArea.vue b/apps/desktop/src/components/layout/ContentArea.vue index 02df3c21d5..9b06181e1d 100644 --- a/apps/desktop/src/components/layout/ContentArea.vue +++ b/apps/desktop/src/components/layout/ContentArea.vue @@ -92,7 +92,7 @@ const props = defineProps<{ activeConnection?: ConnectionConfig; executableSql: string; activeOutputView: "result" | "summary" | "explain" | "chart"; - formatSqlRequestId: number; + formatSqlRequest: { id: number; tabId: string } | null; selectedSql: string; cursorPos: number; }>(); @@ -104,7 +104,7 @@ const emit = defineEmits<{ saveSql: []; cancel: []; explain: []; - editorUpdate: [value: string]; + editorUpdate: [tabId: string, value: string]; editorSelectionChange: [value: string]; editorCursorChange: [pos: number]; formatError: []; @@ -410,9 +410,9 @@ defineExpose({ focusSearch, refreshData, handleModRTarget }); :database-type="activeEffectiveDatabaseType" :dialect="editorDialect" :format-dialect="activeSqlFormatDialect" - :format-request-id="formatSqlRequestId" + :format-request-id="formatSqlRequest?.tabId === activeTab.id ? formatSqlRequest.id : undefined" :execution-error="activeQueryError" - @update:model-value="emit('editorUpdate', $event)" + @update:model-value="emit('editorUpdate', activeTab.id, $event)" @selection-change="emit('editorSelectionChange', $event)" @cursor-change="emit('editorCursorChange', $event)" @format-error="emit('formatError')"