fix(sql-file): open and save custom-filtered text files

This commit is contained in:
zipg authored and GitHub committed 2026-09-02 11:55:00 +08:00
1 parent d3a6a69796
commit 9b6f3c48e4
8 files changed
+113 -58

No files matched your search

+7 -2
View File
@@ -62,7 +62,7 @@ import { isMacOS, isWindows } from "@/lib/backend/platform";
import { isTauriRuntime } from "@/lib/backend/tauriRuntime";
import { openQueryResultArchiveFile } from "@/lib/query/queryResultArchiveFile";
import { rememberExternalSqlFileTarget, resolveExternalSqlFileTarget, unassociatedExternalSqlFileTarget } from "@/lib/sql/externalSqlFileTarget";
import { externalSqlFileOpenErrorMessage, readBrowserSqlFile, sqlFileTitleFromPath } from "@/lib/sql/sqlFileOpen";
import { externalSqlFileOpenErrorMessage, isSqlFilePath, readBrowserSqlFile, sqlFileTitleFromPath } from "@/lib/sql/sqlFileOpen";
import type { ConnectionConfig, DatabaseType, ObjectSourceKind, QueryTab, TreeNode } from "@/types/database";
import { parseConnectionDeepLink, type ConnectionDeepLinkDraft } from "@/lib/connection/connectionDeepLink";
import { parseAiConfigDeepLink, type AiConfigDeepLinkDraft } from "@/lib/ai/aiConfigDeepLink";
@@ -1311,6 +1311,7 @@ function savedSqlTargetForSave(tab: QueryTab) {
*/
async function formattedSqlForSave(tab: QueryTab): Promise<string> {
if (!settingsStore.editorSettings.formatSqlOnSqlFileSave) return tab.sql;
if (tab.externalSqlPath && !isSqlFilePath(tab.externalSqlPath)) return tab.sql;
const sqlSnapshot = tab.sql;
if (!sqlSnapshot.trim()) return sqlSnapshot;
const connection = connectionStore.getConfig(tab.connectionId);
@@ -1590,7 +1591,11 @@ async function confirmSaveSqlToLibrary() {
async function saveExternalSqlTabAs(tab: QueryTab): Promise<boolean> {
if (!canSaveSqlTab(tab) || !isTauriRuntime()) return false;
try {
const saved = await api.saveExternalSqlFile(defaultSavedSqlName(tab.title), await formattedSqlForSave(tab));
// Non-SQL external tabs (custom-filtered text files) keep their own file
// name and extension when saving a copy instead of being forced to .sql.
const currentFileName = tab.externalSqlPath?.split(/[\\/]/).pop()?.trim() ?? "";
const filterExtension = currentFileName.includes(".") ? currentFileName.split(".").pop()?.toLowerCase() : undefined;
const saved = await api.saveExternalSqlFile(currentFileName || defaultSavedSqlName(tab.title), await formattedSqlForSave(tab), filterExtension);
if (!saved) return false;
queryStore.linkExternalSqlPath(tab.id, saved.path, sqlFileTitleFromPath(saved.path), saved.version);
rememberExternalSqlFileTarget(saved.path, { connectionId: tab.connectionId, database: tab.database, catalog: tab.catalog, schema: tab.schema });