Skip to content

armgit / dbx

Public Imported from GitHub
0

25 MB lightweight cross-platform database client for 100+ databases, including MySQL, PostgreSQL, SQLite, Redis, MongoDB, DuckDB, SQL Server, and Dameng. Built-in AI, MCP Server, CLI, desktop and Docker. | 轻量级跨平台数据库管理工具,支持 MySQL、PostgreSQL、SQLite、Redis、MongoDB、达梦等 100+ 数据库,提供桌面端、Docker、CLI、内置 AI 助手和 MCP。

fix(editor): scope SQL formatting to active tab

t8y2a414183ff051
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<InstanceType<typeof ContentArea> | 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')"