feat: synchronize tab titles with saved SQL file renaming (#2739)

- Bidirectional sync between SQL library and tab titles
- Case-insensitive .sql extension via shared ensureSqlExtension
- Revert tab title when rename persistence fails

Close #2648

Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
一颗红心andCursor authored and GitHub committed 2026-07-07 18:09:01 +08:00
1 parent b49638ff1e
commit 184e235999
6 files changed
+166 -11

No files matched your search

+14 -1
View File
@@ -46,6 +46,7 @@ import { useConnectionStore } from "@/stores/connectionStore";
import { useSettingsStore } from "@/stores/settingsStore";
import { useSavedSqlStore } from "@/stores/savedSqlStore";
import { createSavedSqlEditorPosition, initSavedSqlEditorPositions, restoreSavedSqlEditorPosition, saveSavedSqlEditorPosition } from "@/lib/app/savedSqlEditorPosition";
import { ensureSqlExtension } from "@/lib/savedSql/savedSqlFileName";
import { safeLocalStorageGet, safeLocalStorageRemove } from "@/lib/backend/safeStorage";
import type { SavedSqlFile } from "@/types/database";
@@ -1468,8 +1469,20 @@ export const useQueryStore = defineStore("query", () => {
if (!trimmed) return false;
const tab = tabs.value.find((t) => t.id === id);
if (!tab || tab.mode !== "query") return false;
tab.title = trimmed;
const normalizedTitle = tab.savedSqlId ? ensureSqlExtension(trimmed) : trimmed;
const previousTitle = tab.title;
tab.title = normalizedTitle;
tab.customTitle = true;
if (tab.savedSqlId) {
const savedSqlStore = useSavedSqlStore();
const existing = savedSqlStore.getFile(tab.savedSqlId);
if (existing && existing.name !== normalizedTitle) {
void savedSqlStore.renameFile(tab.savedSqlId, normalizedTitle).catch((error) => {
console.warn("[DBX][saved-sql:rename:error]", error);
tab.title = previousTitle;
});
}
}
return true;
}
+13 -1
View File
@@ -3,6 +3,7 @@ import { computed, ref } from "vue";
import { uuid } from "@/lib/common/utils";
import * as api from "@/lib/backend/api";
import { forgetSavedSqlEditorPosition } from "@/lib/app/savedSqlEditorPosition";
import { ensureSqlExtension } from "@/lib/savedSql/savedSqlFileName";
import { isTauriRuntime } from "@/lib/backend/tauriRuntime";
import { useSettingsStore } from "@/stores/settingsStore";
import type { SavedSqlFile, SavedSqlFolder, SavedSqlLibrary } from "@/types/database";
@@ -258,9 +259,20 @@ export const useSavedSqlStore = defineStore("savedSql", () => {
async function renameFile(id: string, name: string) {
const existing = getFile(id);
if (!existing) return;
const saved = await api.saveSavedSqlFile({ ...existing, name, updatedAt: nowIso() });
const normalizedName = ensureSqlExtension(name);
const saved = await api.saveSavedSqlFile({ ...existing, name: normalizedName, updatedAt: nowIso() });
files.value = files.value.map((file) => (file.id === id ? { ...saved, sql: file.sql, sqlLoaded: file.sqlLoaded } : file));
bumpVersion();
const { useQueryStore } = await import("@/stores/queryStore");
const queryStore = useQueryStore();
for (const tab of queryStore.tabs) {
if (tab.savedSqlId === id) {
tab.title = saved.name;
tab.customTitle = true;
}
}
await syncToLocalDirectory();
}