fix(query): isolate duplicated tab rename state

This commit is contained in:
GIWTO authored and GitHub committed 2026-07-29 01:05:23 +08:00
1 parent 234f26ada8
commit b7e3b2ee57
3 files changed
+28 -3

No files matched your search

@@ -129,8 +129,12 @@ function startRenameTab(tab: QueryTab) {
editingTitle.value = tab.title; editingTitle.value = tab.title;
nextTick(() => { nextTick(() => {
const input = document.querySelector<HTMLInputElement>(`[data-tab-title-input="${tab.id}"]`); const input = document.querySelector<HTMLInputElement>(`[data-tab-title-input="${tab.id}"]`);
input?.focus(); if (input) {
input?.select(); input.focus();
const dotIndex = input.value.lastIndexOf(".");
const selectEnd = dotIndex > 0 ? dotIndex : input.value.length;
input.setSelectionRange(0, selectEnd);
}
}); });
} }
+3 -1
View File
@@ -1933,7 +1933,9 @@ export const useQueryStore = defineStore("query", () => {
database: original.database, database: original.database,
schema: original.schema, schema: original.schema,
sql: original.sql, sql: original.sql,
savedSqlId: original.savedSqlId, originalSql: "",
savedSqlId: undefined,
externalSqlPath: undefined,
lastExecutedSql: undefined, lastExecutedSql: undefined,
resultBaseSql: original.resultBaseSql, resultBaseSql: original.resultBaseSql,
resultSortedSql: undefined, resultSortedSql: undefined,
+19
View File
@@ -6119,6 +6119,25 @@ test("duplicating a table structure tab clones its unsaved draft", () => {
assert.equal(tab.structureDraft.columns[0]!.name, "draft_name"); assert.equal(tab.structureDraft.columns[0]!.name, "draft_name");
}); });
test("duplicateTab does not inherit savedSqlId or externalSqlPath", () => {
setActivePinia(createPinia());
const store = useQueryStore();
const tabId = store.createTab("conn-1", "db", "A", "query");
const tab = store.tabs.find((t) => t.id === tabId)!;
tab.savedSqlId = "saved-sql-1";
tab.externalSqlPath = "/path/to/sql";
tab.sql = "SELECT 1;";
store.duplicateTab(tabId);
const copy = store.tabs.find((item) => item.id !== tabId)!;
assert.equal(copy.savedSqlId, undefined);
assert.equal(copy.externalSqlPath, undefined);
assert.equal(copy.originalSql, "");
assert.equal(store.isTabDirty(copy), true);
});
test("reorderTab keeps pinned tabs before unpinned tabs after reorder", () => { test("reorderTab keeps pinned tabs before unpinned tabs after reorder", () => {
setActivePinia(createPinia()); setActivePinia(createPinia());
const store = useQueryStore(); const store = useQueryStore();