mirror of
https://github.com/t8y2/dbx.git
synced 2026-10-23 02:40:11 +00:00
fix(editor): scope SQL formatting to active tab
This commit is contained in:
@@ -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'))"
|
||||
|
||||
@@ -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')"
|
||||
|
||||
Reference in New Issue
Block a user