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。
TypeScript aicliclickhousedatabasedatabase-clientdatabase-managementdockerguimcpmongodbmysqlpostgresqlredisrustsql-serversqlitetaurivue
feat(settings): open tables in a detached window
弈秋8f33b37ab5ca
diff --git a/apps/desktop/src/App.vue b/apps/desktop/src/App.vueindex c65b944adf..c41f03f114 100644--- a/apps/desktop/src/App.vue+++ b/apps/desktop/src/App.vue@@ -231,6 +231,7 @@ import { useBackgroundImage } from "@/composables/useBackgroundImage";import ExternalSqlFileChangeDialog from "@/components/editor/ExternalSqlFileChangeDialog.vue";import { resolveWindowContext } from "@/lib/app/windowContext";import { openDetachedTabWindow } from "@/lib/app/detachedTabWindow";+import { DETACH_TAB_REQUEST_EVENT, type DetachTabRequestDetail } from "@/lib/tabs/detachedTableOpen";import { FLOATING_OPEN_FILESYSTEM_EVENT, FLOATING_OPEN_WORKBENCH_EVENT, type FloatingOpenFilesystemPayload, type FloatingOpenWorkbenchPayload } from "@/lib/plugins/pluginFloatingWindow";import { OPEN_PLUGIN_AI_CONVERSATION, type AiPluginConversationRequest } from "@/lib/ai/aiPluginConversation";import type { PluginAiRecommendationHostUpdate } from "@/lib/plugins/pluginHostBridge";@@ -933,6 +934,15 @@ async function detachTab(tab: QueryTab, position?: { x: number; y: number }) {}}+// #13308: table tabs opened while "open tables in a detached window" is on ask+// to be detached once their first load settles.+function handleDetachTabRequest(event: Event) {+ const detail = (event as CustomEvent<DetachTabRequestDetail>).detail;+ if (!detail?.tabId) return;+ const tab = queryStore.tabs.find((entry) => entry.id === detail.tabId);+ if (tab) void detachTab(tab);+}+watch(() => activeTab.value?.mode,(mode) => {@@ -5188,6 +5198,7 @@ onMounted(async () => {window.addEventListener("keydown", handleTabSwitcherKeydownCapture, true);window.addEventListener("keydown", handleAuxiliarySearchKeydownCapture, true);window.addEventListener("keydown", handleKeydown);+ window.addEventListener(DETACH_TAB_REQUEST_EVENT, handleDetachTabRequest as EventListener);window.addEventListener(DBX_VIM_ACTION_EVENT, handleVimDbxAppAction);window.addEventListener("keyup", handleKeyup, true);window.addEventListener("blur", handleTabSwitcherWindowBlur);diff --git a/apps/desktop/src/components/editor/EditorSettingsDialog.vue b/apps/desktop/src/components/editor/EditorSettingsDialog.vueindex a0c0986caa..ddbd611a1e 100644--- a/apps/desktop/src/components/editor/EditorSettingsDialog.vue+++ b/apps/desktop/src/components/editor/EditorSettingsDialog.vue@@ -1000,6 +1000,7 @@ function clearRememberedConnectionDatabases() {}const editDataTabReuseMode = ref<DataTabReuseMode>(settingsStore.editorSettings.dataTabReuseMode);const editOpenDataTabsNextToActive = ref(settingsStore.editorSettings.openDataTabsNextToActive);+const editOpenTablesInDetachedWindow = ref(settingsStore.editorSettings.openTablesInDetachedWindow);const editPrefillNewQueryWithSelect = ref(settingsStore.editorSettings.prefillNewQueryWithSelect);const editOpenQueryOnConnectionOpen = ref(settingsStore.editorSettings.openQueryOnConnectionOpen);const editGenerateSqlIncludeDatabaseName = ref(settingsStore.editorSettings.generateSqlIncludeDatabaseName);@@ -1325,6 +1326,7 @@ function currentEditorSettingsDraft(): EditorSettingsDraft {deepLinkConnectionConfirmMode: editDeepLinkConnectionConfirmMode.value,dataTabReuseMode: editDataTabReuseMode.value,openDataTabsNextToActive: editOpenDataTabsNextToActive.value,+ openTablesInDetachedWindow: editOpenTablesInDetachedWindow.value,prefillNewQueryWithSelect: editPrefillNewQueryWithSelect.value,openQueryOnConnectionOpen: editOpenQueryOnConnectionOpen.value,generateSqlIncludeDatabaseName: editGenerateSqlIncludeDatabaseName.value,@@ -2031,6 +2033,7 @@ function syncEditorSettingsDraftFromStore() {editDeepLinkConnectionConfirmMode.value = settingsStore.editorSettings.deepLinkConnectionConfirmMode;editDataTabReuseMode.value = settingsStore.editorSettings.dataTabReuseMode;editOpenDataTabsNextToActive.value = settingsStore.editorSettings.openDataTabsNextToActive;+ editOpenTablesInDetachedWindow.value = settingsStore.editorSettings.openTablesInDetachedWindow;editPrefillNewQueryWithSelect.value = settingsStore.editorSettings.prefillNewQueryWithSelect;editOpenQueryOnConnectionOpen.value = settingsStore.editorSettings.openQueryOnConnectionOpen;editGenerateSqlIncludeDatabaseName.value = settingsStore.editorSettings.generateSqlIncludeDatabaseName;@@ -2205,6 +2208,7 @@ const editorSettingsDraftRefs: EditorSettingsDraftRefMap = {deepLinkConnectionConfirmMode: editDeepLinkConnectionConfirmMode,dataTabReuseMode: editDataTabReuseMode,openDataTabsNextToActive: editOpenDataTabsNextToActive,+ openTablesInDetachedWindow: editOpenTablesInDetachedWindow,prefillNewQueryWithSelect: editPrefillNewQueryWithSelect,openQueryOnConnectionOpen: editOpenQueryOnConnectionOpen,generateSqlIncludeDatabaseName: editGenerateSqlIncludeDatabaseName,@@ -2796,6 +2800,7 @@ function resetDefaultsForTab(tab: SettingsCategory) {editDeepLinkConnectionConfirmMode.value = DEFAULT_EDITOR_SETTINGS.deepLinkConnectionConfirmMode;editDataTabReuseMode.value = DEFAULT_EDITOR_SETTINGS.dataTabReuseMode;editOpenDataTabsNextToActive.value = DEFAULT_EDITOR_SETTINGS.openDataTabsNextToActive;+ editOpenTablesInDetachedWindow.value = DEFAULT_EDITOR_SETTINGS.openTablesInDetachedWindow;editPrefillNewQueryWithSelect.value = DEFAULT_EDITOR_SETTINGS.prefillNewQueryWithSelect;editOpenQueryOnConnectionOpen.value = DEFAULT_EDITOR_SETTINGS.openQueryOnConnectionOpen;editGenerateSqlIncludeDatabaseName.value = DEFAULT_EDITOR_SETTINGS.generateSqlIncludeDatabaseName;@@ -3022,6 +3027,7 @@ function resetAllDefaults() {editDeepLinkConnectionConfirmMode.value = DEFAULT_EDITOR_SETTINGS.deepLinkConnectionConfirmMode;editDataTabReuseMode.value = DEFAULT_EDITOR_SETTINGS.dataTabReuseMode;editOpenDataTabsNextToActive.value = DEFAULT_EDITOR_SETTINGS.openDataTabsNextToActive;+ editOpenTablesInDetachedWindow.value = DEFAULT_EDITOR_SETTINGS.openTablesInDetachedWindow;editPrefillNewQueryWithSelect.value = DEFAULT_EDITOR_SETTINGS.prefillNewQueryWithSelect;editOpenQueryOnConnectionOpen.value = DEFAULT_EDITOR_SETTINGS.openQueryOnConnectionOpen;editGenerateSqlIncludeDatabaseName.value = DEFAULT_EDITOR_SETTINGS.generateSqlIncludeDatabaseName;@@ -9194,6 +9200,15 @@ onUnmounted(() => {</div><Switch id="open-data-tabs-next-to-active" v-model="editOpenDataTabsNextToActive" /></div>+ <div class="settings-item flex items-center justify-between gap-4 rounded-md border bg-muted/20 px-3 py-2">+ <div class="flex items-center gap-2">+ <Label for="open-tables-in-detached-window">{{ t("settings.openTablesInDetachedWindow") }}</Label>+ <HelpTooltip :label="t('settings.openTablesInDetachedWindow')">+ {{ t("settings.openTablesInDetachedWindowDescription") }}+ </HelpTooltip>+ </div>+ <Switch id="open-tables-in-detached-window" v-model="editOpenTablesInDetachedWindow" />+ </div><div class="space-y-2"><Label>{{ t("settings.sidebarObjectDisplay") }}</Label><div class="grid grid-cols-2 gap-2">diff --git a/apps/desktop/src/composables/__tests__/useSidebarDataOpenRuntime.spec.ts b/apps/desktop/src/composables/__tests__/useSidebarDataOpenRuntime.spec.tsindex 6145601c0b..a1aaff5627 100644--- a/apps/desktop/src/composables/__tests__/useSidebarDataOpenRuntime.spec.ts+++ b/apps/desktop/src/composables/__tests__/useSidebarDataOpenRuntime.spec.ts@@ -1,4 +1,5 @@import { beforeEach, describe, expect, it, vi } from "vitest";+import { reactive } from "vue";import { useSidebarDataOpenRuntime } from "@/composables/useSidebarDataOpenRuntime";import { markRowIdLocatorUnsupported, resetRowIdLocatorStateForTests, rowIdLocatorUnsupported } from "@/lib/table/tableRowIdSupport";import type { DataTabReuseMode } from "@/lib/tabs/dataTabReuseMode";@@ -23,6 +24,9 @@ const mocks = vi.hoisted(() => ({buildTableSelectSql: vi.fn(),setErrorResult: vi.fn(),cancelTabExecution: vi.fn(),+ tauriRuntime: true,+ openTablesInDetachedWindow: false,+ detachDispatch: vi.fn(),}));vi.mock("@/stores/connectionStore", () => ({@@ -49,7 +53,9 @@ vi.mock("@/stores/queryStore", () => ({return existing.id;}}- const tab = {+ // 与真实 store 一致:tab 是响应式对象,settle watcher 才能观察到+ // isExecuting/result 的变化(#13308 detached open 依赖此行为)。+ const tab = reactive({id: `tab-${mocks.tabs.length + 1}`,connectionId,database,@@ -62,7 +68,7 @@ vi.mock("@/stores/queryStore", () => ({isExecuting: false,isCancelling: false,isExplaining: false,- } as QueryTab;+ }) as QueryTab;const activeIndex = options.insertAfterActive ? mocks.tabs.findIndex((item) => item.id === mocks.activeTabId) : -1;if (activeIndex >= 0) mocks.tabs.splice(activeIndex + 1, 0, tab);else mocks.tabs.push(tab);@@ -108,13 +114,36 @@ vi.mock("@/stores/queryStore", () => ({}));vi.mock("@/stores/settingsStore", () => ({- useSettingsStore: () => ({ editorSettings: { tableOpenSortMode: mocks.tableOpenSortMode, tableDatabaseSortDirection: "desc", tableLocalSortDirection: "asc", dataTabReuseMode: mocks.dataTabReuseMode, openDataTabsNextToActive: mocks.openDataTabsNextToActive, pageSize: 100 } }),+ useSettingsStore: () => ({+ editorSettings: {+ tableOpenSortMode: mocks.tableOpenSortMode,+ tableDatabaseSortDirection: "desc",+ tableLocalSortDirection: "asc",+ dataTabReuseMode: mocks.dataTabReuseMode,+ openDataTabsNextToActive: mocks.openDataTabsNextToActive,+ openTablesInDetachedWindow: mocks.openTablesInDetachedWindow,+ pageSize: 100,+ },+ }),}));vi.mock("@/stores/tunnelProfileStore", () => ({useTunnelProfileStore: () => ({ profileById: () => undefined }),}));+// The detached-open settle logic itself is the real implementation; only the+// desktop gate and the dispatch destination are rerouted so the watcher's+// behavior stays observable in the node test environment.+vi.mock("@/lib/backend/tauriRuntime", () => ({ isTauriRuntime: () => mocks.tauriRuntime }));++vi.mock("@/lib/tabs/detachedTableOpen", async (importOriginal) => {+ const actual = await importOriginal<typeof import("@/lib/tabs/detachedTableOpen")>();+ return {+ ...actual,+ requestDetachedTableOpen: (getTab: () => QueryTab | undefined) => actual.requestDetachedTableOpen(getTab, mocks.detachDispatch),+ };+});+vi.mock("@/lib/database/jdbcDialect", () => ({effectiveDatabaseTypeForConnection: () => mocks.databaseType,connectionObjectTreeNodeSchema: (_config: unknown, _database: string, schema?: string) => schema,@@ -179,6 +208,8 @@ describe("useSidebarDataOpenRuntime", () => {mocks.openDataTabsNextToActive = false;mocks.metadataGeneration = 0;mocks.includeSyntheticRowId = false;+ mocks.tauriRuntime = true;+ mocks.openTablesInDetachedWindow = false;resetRowIdLocatorStateForTests();mocks.ensureConnected.mockResolvedValue(undefined);mocks.buildTableSelectSql.mockResolvedValue("SELECT * FROM users");@@ -540,6 +571,67 @@ describe("useSidebarDataOpenRuntime", () => {expect(mocks.tabs.map((tab) => tab.title)).toEqual(["users", "orders"]);});+ it("requests the detached open once after a fresh table tab's first load settles", async () => {+ mocks.openTablesInDetachedWindow = true;+ mocks.executeTabSql.mockImplementation(async (tabId: string) => {+ const tab = mocks.tabs.find((candidate) => candidate.id === tabId)!;+ tab.isExecuting = false;+ tab.executionId = undefined;+ tab.result = { columns: ["id"], rows: [[1]], affected_rows: 0, execution_time_ms: 0 } as any;+ return true;+ });++ await useSidebarDataOpenRuntime().openData(tableNode);+ await new Promise((resolve) => setTimeout(resolve, 0));++ expect(mocks.tabs).toHaveLength(1);+ expect(mocks.detachDispatch).toHaveBeenCalledExactlyOnceWith({ tabId: "tab-1" });+ });++ it("detaches a reused tab only after the fresh reload settles, not on its stale errored result", async () => {+ mocks.openTablesInDetachedWindow = true;+ // First open fails: the same-table tab keeps the errored result and idles.+ mocks.executeTabSql.mockImplementation(async (tabId: string) => {+ const tab = mocks.tabs.find((candidate) => candidate.id === tabId)!;+ tab.isExecuting = false;+ tab.executionId = undefined;+ tab.result = { columns: ["Error"], execution_error: true, rows: [["boom"]], affected_rows: 0, execution_time_ms: 0 } as any;+ return true;+ });+ await useSidebarDataOpenRuntime().openData(tableNode);+ await new Promise((resolve) => setTimeout(resolve, 0));+ expect(mocks.tabs).toHaveLength(1);+ mocks.detachDispatch.mockClear();++ // Second open of the same table reuses the errored tab and reloads it.+ let resolveSecondLoad: ((publishResult: boolean) => void) | undefined;+ mocks.executeTabSql.mockImplementation((tabId: string) => {+ const tab = mocks.tabs.find((candidate) => candidate.id === tabId)!;+ return new Promise<boolean>((resolve) => {+ resolveSecondLoad = (publishResult: boolean) => {+ tab.isExecuting = false;+ tab.executionId = undefined;+ if (publishResult) {+ tab.result = { columns: ["id"], rows: [[1]], affected_rows: 0, execution_time_ms: 0 } as any;+ }+ resolve(true);+ };+ });+ });++ const opened = useSidebarDataOpenRuntime().openData(tableNode);+ await new Promise((resolve) => setTimeout(resolve, 0));+ // The stale errored result must not satisfy the settle check: no detach+ // while the fresh reload is still in flight.+ expect(mocks.tabs).toHaveLength(1);+ expect(mocks.detachDispatch).not.toHaveBeenCalled();++ resolveSecondLoad!(true);+ await opened;+ await new Promise((resolve) => setTimeout(resolve, 0));+ expect(mocks.detachDispatch).toHaveBeenCalledExactlyOnceWith({ tabId: "tab-1" });+ });+it("opens a new table data tab next to the active tab when enabled", async () => {mocks.openDataTabsNextToActive = true;mocks.tabs.push(diff --git a/apps/desktop/src/composables/useSidebarDataOpenRuntime.ts b/apps/desktop/src/composables/useSidebarDataOpenRuntime.tsindex e76dc94241..4bf7914830 100644--- a/apps/desktop/src/composables/useSidebarDataOpenRuntime.ts+++ b/apps/desktop/src/composables/useSidebarDataOpenRuntime.ts@@ -2,6 +2,7 @@ import { nextTick } from "vue";import { useConnectionStore } from "@/stores/connectionStore";import { useQueryStore } from "@/stores/queryStore";import { useSettingsStore } from "@/stores/settingsStore";+import { requestDetachedTableOpen } from "@/lib/tabs/detachedTableOpen";import { useTunnelProfileStore } from "@/stores/tunnelProfileStore";import type { TreeNode } from "@/types/database";import { uuid } from "@/lib/common/utils";@@ -334,6 +335,13 @@ export function useSidebarDataOpenRuntime() {if (pendingTab) pendingTab.tableMetaPending = true;}queryStore.setExecutingWithId(tabId, openDataId);+ // #13308: with the detached-open setting on, the freshly opened table moves+ // into its own window once the first load settles. Ask only after the reused+ // tab's previous result is cleared and this load is scheduled, so a stale+ // errored result cannot satisfy the settle check before the reload starts.+ if (settingsStore.editorSettings.openTablesInDetachedWindow) {+ requestDetachedTableOpen(() => queryStore.tabs.find((entry) => entry.id === tabId));+ }request?.registerCancel(async () => {const current = queryStore.tabs.find((item) => item.id === tabId);if (current?.isExecuting && current.executionId === openDataId) {diff --git a/apps/desktop/src/i18n/locales/az.ts b/apps/desktop/src/i18n/locales/az.tsindex 006bc3f88b..80306e6b2a 100644--- a/apps/desktop/src/i18n/locales/az.ts+++ b/apps/desktop/src/i18n/locales/az.ts@@ -7911,6 +7911,8 @@ export default withEnglishFallback({reuseDataTabDescription: "Cədvəl açılarkən verilənlər vərəqlərindən necə istifadə olunacağını seçin.",openDataTabsNextToActive: "Yeni verilənlər vərəqlərini aktiv vərəqin yanında aç",openDataTabsNextToActiveDescription: "Yeni yaradılmış cədvəl verilənləri vərəqlərini aktiv vərəqdən dərhal sonra yerləşdir.",+ openTablesInDetachedWindow: "Cədvəlləri ayrı pəncərədə aç",+ openTablesInDetachedWindowDescription: "Cədvəl məlumatını əsas pəncərə sekmesi yerinə öz pəncərəsində açır.",dataTabReuseAlwaysNew: "Həmişə yeni vərəq aç",dataTabReuseAlwaysNewDescription: "Cədvəl artıq açıq olsa belə, hər dəfə yeni verilənlər vərəqi yarat.",dataTabReuseSameTable: "Eyni cədvəldən təkrar istifadə et",diff --git a/apps/desktop/src/i18n/locales/en.ts b/apps/desktop/src/i18n/locales/en.tsindex 39192248d3..3f8c8e8bc5 100644--- a/apps/desktop/src/i18n/locales/en.ts+++ b/apps/desktop/src/i18n/locales/en.ts@@ -10116,6 +10116,8 @@ export default {reuseDataTabDescription: "Choose how opening a table uses data tabs.",openDataTabsNextToActive: "Open new data tabs next to the active tab",openDataTabsNextToActiveDescription: "Place newly created table data tabs immediately after the active tab.",+ openTablesInDetachedWindow: "Open tables in a detached window",+ openTablesInDetachedWindowDescription: "Open table data directly in its own window instead of a main-window tab.",dataTabReuseAlwaysNew: "Always open a new tab",dataTabReuseAlwaysNewDescription: "Create a new data tab every time, even when the table is already open.",dataTabReuseSameTable: "Reuse the same table",diff --git a/apps/desktop/src/i18n/locales/es.ts b/apps/desktop/src/i18n/locales/es.tsindex f476092fb2..a54541140d 100644--- a/apps/desktop/src/i18n/locales/es.ts+++ b/apps/desktop/src/i18n/locales/es.ts@@ -8954,6 +8954,8 @@ export default withEnglishFallback({reuseDataTabDescription: "Elige cómo se usan las pestañas de datos al abrir una tabla.",openDataTabsNextToActive: "Abrir nuevas pestañas de datos junto a la activa",openDataTabsNextToActiveDescription: "Coloca las nuevas pestañas de datos de tablas justo después de la pestaña activa.",+ openTablesInDetachedWindow: "Abrir tablas en una ventana independiente",+ openTablesInDetachedWindowDescription: "Abrir los datos de la tabla en su propia ventana en lugar de una pestaña.",dataTabReuseAlwaysNew: "Abrir siempre una pestaña nueva",dataTabReuseAlwaysNewDescription: "Crea una pestaña de datos nueva cada vez, aunque la tabla ya esté abierta.",dataTabReuseSameTable: "Reutilizar solo la misma tabla",diff --git a/apps/desktop/src/i18n/locales/id.ts b/apps/desktop/src/i18n/locales/id.tsindex 2db65916e2..4316706a93 100644--- a/apps/desktop/src/i18n/locales/id.ts+++ b/apps/desktop/src/i18n/locales/id.ts@@ -8679,6 +8679,8 @@ export default withEnglishFallback({reuseDataTabDescription: "Pilih bagaimana membuka tabel menggunakan tab data.",openDataTabsNextToActive: "Buka tab data baru di sebelah tab aktif",openDataTabsNextToActiveDescription: "Tempatkan tab data tabel yang baru dibuat tepat setelah tab aktif.",+ openTablesInDetachedWindow: "Buka tabel di jendela terpisah",+ openTablesInDetachedWindowDescription: "Membuka data tabel di jendelanya sendiri, bukan tab jendela utama.",dataTabReuseAlwaysNew: "Selalu buka tab baru",dataTabReuseAlwaysNewDescription: "Buat tab data baru setiap kali, bahkan jika tabel tersebut sudah terbuka.",dataTabReuseSameTable: "Gunakan kembali tabel yang sama",diff --git a/apps/desktop/src/i18n/locales/it.ts b/apps/desktop/src/i18n/locales/it.tsindex ee4b8b9458..8f039b5b41 100644--- a/apps/desktop/src/i18n/locales/it.ts+++ b/apps/desktop/src/i18n/locales/it.ts@@ -8733,6 +8733,8 @@ export default withEnglishFallback({reuseDataTabDescription: "Scegli come usare le schede dati quando apri una tabella.",openDataTabsNextToActive: "Apri le nuove schede dati accanto a quella attiva",openDataTabsNextToActiveDescription: "Posiziona le nuove schede dati delle tabelle subito dopo la scheda attiva.",+ openTablesInDetachedWindow: "Apri le tabelle in una finestra dedicata",+ openTablesInDetachedWindowDescription: "Apre i dati della tabella in una finestra dedicata invece di una scheda.",dataTabReuseAlwaysNew: "Apri sempre una nuova scheda",dataTabReuseAlwaysNewDescription: "Crea ogni volta una nuova scheda dati, anche se la tabella è già aperta.",dataTabReuseSameTable: "Riusa solo la stessa tabella",diff --git a/apps/desktop/src/i18n/locales/ja.ts b/apps/desktop/src/i18n/locales/ja.tsindex 0fdbab6af8..10ff5cb9af 100644--- a/apps/desktop/src/i18n/locales/ja.ts+++ b/apps/desktop/src/i18n/locales/ja.ts@@ -8737,6 +8737,8 @@ export default withEnglishFallback({reuseDataTabDescription: "テーブルを開くときのデータタブの使い方を選択します。",openDataTabsNextToActive: "新しいデータタブをアクティブタブの隣に開く",openDataTabsNextToActiveDescription: "新しく作成したテーブルのデータタブをアクティブタブの直後に配置します。",+ openTablesInDetachedWindow: "テーブルを独立ウィンドウで開く",+ openTablesInDetachedWindowDescription: "テーブルデータをメインウィンドウのタブではなく独立ウィンドウで開きます。",dataTabReuseAlwaysNew: "常に新しいタブを開く",dataTabReuseAlwaysNewDescription: "同じテーブルが開いていても、毎回新しいデータタブを作成します。",dataTabReuseSameTable: "同じテーブルだけ再利用",diff --git a/apps/desktop/src/i18n/locales/ko.ts b/apps/desktop/src/i18n/locales/ko.tsindex 2ead1a5b30..d620a25830 100644--- a/apps/desktop/src/i18n/locales/ko.ts+++ b/apps/desktop/src/i18n/locales/ko.ts@@ -8855,6 +8855,8 @@ export default withEnglishFallback({reuseDataTabDescription: "테이블을 열 때 데이터 탭을 사용하는 방식을 선택합니다.",openDataTabsNextToActive: "새 데이터 탭을 활성 탭 옆에 열기",openDataTabsNextToActiveDescription: "새로 만든 테이블 데이터 탭을 활성 탭 바로 뒤에 배치합니다.",+ openTablesInDetachedWindow: "테이블을 독립 창으로 열기",+ openTablesInDetachedWindowDescription: "테이블 데이터를 메인 창 탭 대신 독립 창에서 엽니다.",dataTabReuseAlwaysNew: "항상 새 탭 열기",dataTabReuseAlwaysNewDescription: "테이블이 이미 열려 있어도 매번 새 데이터 탭을 만듭니다.",dataTabReuseSameTable: "같은 테이블만 재사용",diff --git a/apps/desktop/src/i18n/locales/pl.ts b/apps/desktop/src/i18n/locales/pl.tsindex 284d4024cb..bf4e68ec87 100644--- a/apps/desktop/src/i18n/locales/pl.ts+++ b/apps/desktop/src/i18n/locales/pl.ts@@ -8751,6 +8751,8 @@ export default withEnglishFallback({reuseDataTabDescription: "Wybierz sposób otwierania tabel w kartach danych.",openDataTabsNextToActive: "Otwieraj nowe karty danych obok aktywnej karty",openDataTabsNextToActiveDescription: "Umieszczaj nowo utworzone karty danych tabeli bezpośrednio za aktualnie aktywną kartą.",+ openTablesInDetachedWindow: "Otwieraj tabele w osobnym oknie",+ openTablesInDetachedWindowDescription: "Otwiera dane tabeli w osobnym oknie zamiast karty w oknie głównym.",dataTabReuseAlwaysNew: "Zawsze otwieraj nową kartę",dataTabReuseAlwaysNewDescription: "Twórz nową kartę danych za każdym razem, nawet jeśli tabela jest już otwarta.",dataTabReuseSameTable: "Używaj ponownie tej samej tabeli",diff --git a/apps/desktop/src/i18n/locales/pt-BR.ts b/apps/desktop/src/i18n/locales/pt-BR.tsindex 732b2911e5..2e0e4f0652 100644--- a/apps/desktop/src/i18n/locales/pt-BR.ts+++ b/apps/desktop/src/i18n/locales/pt-BR.ts@@ -8732,6 +8732,8 @@ export default withEnglishFallback({reuseDataTabDescription: "Escolha como as abas de dados são usadas ao abrir uma tabela.",openDataTabsNextToActive: "Abrir novas abas de dados ao lado da aba ativa",openDataTabsNextToActiveDescription: "Coloca as novas abas de dados de tabelas logo após a aba ativa.",+ openTablesInDetachedWindow: "Abrir tabelas em janela separada",+ openTablesInDetachedWindowDescription: "Abrir os dados da tabela em sua própria janela em vez de uma aba.",dataTabReuseAlwaysNew: "Sempre abrir uma nova aba",dataTabReuseAlwaysNewDescription: "Cria uma nova aba de dados todas as vezes, mesmo que a tabela já esteja aberta.",dataTabReuseSameTable: "Reutilizar apenas a mesma tabela",diff --git a/apps/desktop/src/i18n/locales/ru.ts b/apps/desktop/src/i18n/locales/ru.tsindex 3a5f1ce609..a6ee90aebb 100644--- a/apps/desktop/src/i18n/locales/ru.ts+++ b/apps/desktop/src/i18n/locales/ru.ts@@ -10299,6 +10299,8 @@ export default withEnglishFallback({reuseDataTabDescription: "Выберите, как открытие таблицы использует вкладки данных.",openDataTabsNextToActive: "Открывать новые вкладки данных рядом с активной",openDataTabsNextToActiveDescription: "Размещать новые вкладки данных таблиц сразу после активной вкладки.",+ openTablesInDetachedWindow: "Открывать таблицы в отдельном окне",+ openTablesInDetachedWindowDescription: "Открывать данные таблицы в отдельном окне вместо вкладки главного окна.",dataTabReuseAlwaysNew: "Всегда открывать новую вкладку",dataTabReuseAlwaysNewDescription: "Каждый раз создавать новую вкладку данных, даже если таблица уже открыта.",dataTabReuseSameTable: "Переиспользовать вкладку той же таблицы",diff --git a/apps/desktop/src/i18n/locales/th.ts b/apps/desktop/src/i18n/locales/th.tsindex fe31101bbc..3fdc6f5bf2 100644--- a/apps/desktop/src/i18n/locales/th.ts+++ b/apps/desktop/src/i18n/locales/th.ts@@ -10701,6 +10701,8 @@ export default withEnglishFallback({reuseDataTabDescription: "เลือกวิธีที่การเปิดตารางใช้แท็บข้อมูล",openDataTabsNextToActive: "เปิดแท็บข้อมูลใหม่ถัดจากแท็บที่ใช้งาน",openDataTabsNextToActiveDescription: "วางแท็บข้อมูลตารางที่สร้างใหม่ทันทีหลังแท็บที่ใช้งาน",+ openTablesInDetachedWindow: "เปิดตารางในหน้าต่างแยก",+ openTablesInDetachedWindowDescription: "เปิดข้อมูลตารางในหน้าต่างของตัวเองแทนแท็บหน้าต่างหลัก",dataTabReuseAlwaysNew: "เปิดแท็บใหม่เสมอ",dataTabReuseAlwaysNewDescription: "สร้างแท็บข้อมูลใหม่ทุกครั้ง แม้ตารางจะเปิดอยู่แล้ว",dataTabReuseSameTable: "ใช้ตารางเดิมซ้ำ",diff --git a/apps/desktop/src/i18n/locales/tr.ts b/apps/desktop/src/i18n/locales/tr.tsindex e7dacaf5f7..62360354a8 100644--- a/apps/desktop/src/i18n/locales/tr.ts+++ b/apps/desktop/src/i18n/locales/tr.ts@@ -7819,6 +7819,8 @@ export default withEnglishFallback({reuseDataTabDescription: "Bir tablo açıldığında veri sekmelerinin nasıl kullanılacağını seçin.",openDataTabsNextToActive: "Yeni veri sekmelerini etkin sekmenin yanında aç",openDataTabsNextToActiveDescription: "Yeni oluşturulan tablo veri sekmelerini doğrudan etkin sekmenin ardına yerleştir.",+ openTablesInDetachedWindow: "Tabloları ayrı pencerede aç",+ openTablesInDetachedWindowDescription: "Tablo verilerini ana pencere sekmesi yerine kendi penceresinde açar.",dataTabReuseAlwaysNew: "Her zaman yeni sekme aç",dataTabReuseAlwaysNewDescription: "Tablo zaten açık olsa bile her seferinde yeni bir veri sekmesi oluştur.",dataTabReuseSameTable: "Aynı tabloyu yeniden kullan",diff --git a/apps/desktop/src/i18n/locales/zh-CN.ts b/apps/desktop/src/i18n/locales/zh-CN.tsindex f72b9f0bef..48846c12a9 100644--- a/apps/desktop/src/i18n/locales/zh-CN.ts+++ b/apps/desktop/src/i18n/locales/zh-CN.ts@@ -10083,6 +10083,8 @@ export default withEnglishFallback({reuseDataTabDescription: "选择打开表时如何使用数据标签页。",openDataTabsNextToActive: "在当前标签页旁打开新数据标签页",openDataTabsNextToActiveDescription: "将新建的表数据标签页放在当前标签页之后。",+ openTablesInDetachedWindow: "打开表时使用独立窗口",+ openTablesInDetachedWindowDescription: "直接在独立窗口中打开表数据,而不是主窗口标签页。",dataTabReuseAlwaysNew: "始终新建标签页",dataTabReuseAlwaysNewDescription: "每次打开表都新建标签页,即使该表已经打开。",dataTabReuseSameTable: "仅复用同一张表",diff --git a/apps/desktop/src/i18n/locales/zh-TW.ts b/apps/desktop/src/i18n/locales/zh-TW.tsindex 5aa6df8d30..96aecafbc2 100644--- a/apps/desktop/src/i18n/locales/zh-TW.ts+++ b/apps/desktop/src/i18n/locales/zh-TW.ts@@ -7877,6 +7877,8 @@ export default withEnglishFallback({reuseDataTabDescription: "選擇開啟資料表時如何使用資料分頁。",openDataTabsNextToActive: "在目前分頁旁開啟新的資料分頁",openDataTabsNextToActiveDescription: "將新建的資料表資料分頁放在目前分頁之後。",+ openTablesInDetachedWindow: "開啟表時使用獨立視窗",+ openTablesInDetachedWindowDescription: "直接在獨立視窗中開啟表資料,而不是主視窗分頁。",dataTabReuseAlwaysNew: "一律開啟新分頁",dataTabReuseAlwaysNewDescription: "每次開啟資料表都建立新分頁,即使該資料表已經開啟。",dataTabReuseSameTable: "僅重複使用同一資料表",diff --git a/apps/desktop/src/lib/__tests__/tabs/detachedTableOpen.spec.ts b/apps/desktop/src/lib/__tests__/tabs/detachedTableOpen.spec.tsnew file mode 100644index 0000000000..f6ff74cb4d--- /dev/null+++ b/apps/desktop/src/lib/__tests__/tabs/detachedTableOpen.spec.ts@@ -0,0 +1,96 @@+import { describe, expect, it, vi } from "vitest";+import { reactive } from "vue";+import { requestDetachedTableOpen } from "@/lib/tabs/detachedTableOpen";+import type { QueryTab } from "@/types/database";++const tauriRuntime = vi.hoisted(() => ({ value: true }));+vi.mock("@/lib/backend/tauriRuntime", () => ({ isTauriRuntime: () => tauriRuntime.value }));++function makeTab(overrides: Partial<QueryTab> = {}): QueryTab {+ return reactive({+ id: "tab-1",+ title: "orders",+ connectionId: "conn",+ database: "app",+ mode: "data",+ sql: "",+ isExecuting: false,+ result: undefined,+ ...overrides,+ }) as QueryTab;+}++describe("requestDetachedTableOpen (#13308)", () => {+ it("does nothing outside the Tauri runtime (web gate)", () => {+ tauriRuntime.value = false;+ const dispatch = vi.fn();+ const tab = makeTab({ result: { columns: ["id"], rows: [[1]], affected_rows: 0, execution_time_ms: 1 } });+ requestDetachedTableOpen(() => tab, dispatch);+ expect(dispatch).not.toHaveBeenCalled();+ tauriRuntime.value = true;+ });+ it("dispatches immediately when the tab already settled", () => {+ const dispatch = vi.fn();+ const tab = makeTab({ result: { columns: ["id"], rows: [[1]], affected_rows: 0, execution_time_ms: 1 } });+ requestDetachedTableOpen(() => tab, dispatch);+ expect(dispatch).toHaveBeenCalledExactlyOnceWith({ tabId: "tab-1" });+ });++ it("waits for the first result to land before dispatching", async () => {+ const dispatch = vi.fn();+ const tab = makeTab({ isExecuting: true });+ requestDetachedTableOpen(() => tab, dispatch);+ expect(dispatch).not.toHaveBeenCalled();+ tab.isExecuting = false;+ await Promise.resolve();+ expect(dispatch).not.toHaveBeenCalled();+ tab.result = { columns: ["id"], rows: [[1]], affected_rows: 0, execution_time_ms: 1 };+ await new Promise((resolve) => setTimeout(resolve, 0));+ expect(dispatch).toHaveBeenCalledExactlyOnceWith({ tabId: "tab-1" });+ });++ it("never dispatches for a vanished tab", async () => {+ const dispatch = vi.fn();+ let tab: QueryTab | undefined = makeTab({ isExecuting: true });+ requestDetachedTableOpen(() => tab, dispatch);+ tab = undefined;+ tab = undefined;+ await new Promise((resolve) => setTimeout(resolve, 0));+ expect(dispatch).not.toHaveBeenCalled();+ });++ // A load can end without publishing a result (superseded navigation or a+ // cancelled execution leaves `result` undefined), which keeps the settle+ // check at "loading". The watcher must still stop once the tab is removed.+ // The tab lives in reactive state so the getter can observe the removal, the+ // way `queryStore.tabs` does in the app.+ it("stops the watcher when a load ends without a result and the tab is then removed", async () => {+ const dispatch = vi.fn();+ const holder = reactive<{ tab?: QueryTab }>({ tab: makeTab({ isExecuting: true }) });+ requestDetachedTableOpen(() => holder.tab, dispatch);+ holder.tab!.isExecuting = false;+ await new Promise((resolve) => setTimeout(resolve, 0));+ expect(dispatch).not.toHaveBeenCalled();+ holder.tab = undefined;+ await new Promise((resolve) => setTimeout(resolve, 0));+ expect(dispatch).not.toHaveBeenCalled();+ // Watcher-stopped proof: if the watcher were still alive, a tab reappearing+ // through the getter as settled would trigger a late dispatch.+ holder.tab = makeTab({ result: { columns: ["id"], rows: [[1]], affected_rows: 0, execution_time_ms: 1 } });+ await new Promise((resolve) => setTimeout(resolve, 0));+ expect(dispatch).not.toHaveBeenCalled();+ });++ it("stops the watcher when the tab closes before the load settles", async () => {+ const dispatch = vi.fn();+ const holder = reactive<{ tab?: QueryTab }>({ tab: makeTab({ isExecuting: true }) });+ requestDetachedTableOpen(() => holder.tab, dispatch);+ holder.tab = undefined;+ await new Promise((resolve) => setTimeout(resolve, 0));+ expect(dispatch).not.toHaveBeenCalled();+ // Watcher-stopped proof: a resurrected settled tab must not dispatch late.+ holder.tab = makeTab({ result: { columns: ["id"], rows: [[1]], affected_rows: 0, execution_time_ms: 1 } });+ await new Promise((resolve) => setTimeout(resolve, 0));+ expect(dispatch).not.toHaveBeenCalled();+ });+});diff --git a/apps/desktop/src/lib/settings/editorSettingsDraft.ts b/apps/desktop/src/lib/settings/editorSettingsDraft.tsindex 7bfd238206..51cd346459 100644--- a/apps/desktop/src/lib/settings/editorSettingsDraft.ts+++ b/apps/desktop/src/lib/settings/editorSettingsDraft.ts@@ -129,6 +129,7 @@ export const EDITOR_SETTINGS_DRAFT_KEYS = ["deepLinkConnectionConfirmMode","dataTabReuseMode","openDataTabsNextToActive",+ "openTablesInDetachedWindow","prefillNewQueryWithSelect","openQueryOnConnectionOpen","generateSqlIncludeDatabaseName",diff --git a/apps/desktop/src/lib/settings/settingsSearch.ts b/apps/desktop/src/lib/settings/settingsSearch.tsindex 7c9d625985..9b3bfe7478 100644--- a/apps/desktop/src/lib/settings/settingsSearch.ts+++ b/apps/desktop/src/lib/settings/settingsSearch.ts@@ -362,6 +362,7 @@ export const SETTINGS_SEARCH_DEFINITIONS: readonly SettingsSearchDefinition[] =},{ id: "navigation-reuse-data-tab", category: "navigation", titleKey: "settings.reuseDataTab", descriptionKey: "settings.reuseDataTabDescription", targetId: "navigation" },{ id: "navigation-open-data-tabs-next-to-active", category: "navigation", titleKey: "settings.openDataTabsNextToActive", descriptionKey: "settings.openDataTabsNextToActiveDescription", targetId: "navigation" },+ { id: "navigation-open-tables-in-detached-window", category: "navigation", titleKey: "settings.openTablesInDetachedWindow", descriptionKey: "settings.openTablesInDetachedWindowDescription", targetId: "navigation" },{ id: "navigation-object-display", category: "navigation", titleKey: "settings.sidebarObjectDisplay", targetId: "navigation" },{id: "navigation-object-info",diff --git a/apps/desktop/src/lib/settings/settingsTransfer.ts b/apps/desktop/src/lib/settings/settingsTransfer.tsindex deed15cb6e..16d0cd8437 100644--- a/apps/desktop/src/lib/settings/settingsTransfer.ts+++ b/apps/desktop/src/lib/settings/settingsTransfer.ts@@ -210,6 +210,7 @@ const SETTINGS_TRANSFER_CATEGORY_KEYS: Record<SettingsTransferCategoryId, readon"deepLinkConnectionConfirmMode","dataTabReuseMode","openDataTabsNextToActive",+ "openTablesInDetachedWindow","clickTableNavigationTarget","objectBrowserAutoOpenDetailPanel","sidebarObjectInfoMode",diff --git a/apps/desktop/src/lib/tabs/detachedTableOpen.ts b/apps/desktop/src/lib/tabs/detachedTableOpen.tsnew file mode 100644index 0000000000..a6d8b908a2--- /dev/null+++ b/apps/desktop/src/lib/tabs/detachedTableOpen.ts@@ -0,0 +1,55 @@+import { watch } from "vue";+import { isTauriRuntime } from "@/lib/backend/tauriRuntime";+import type { QueryTab } from "@/types/database";++/** Window event asking the main window to detach a freshly opened table tab. */+export const DETACH_TAB_REQUEST_EVENT = "dbx:detach-tab-request";++export interface DetachTabRequestDetail {+ tabId: string;+}++/** Terminal/intermediate states of the settle check the watcher observes. */+type DetachSettleState = "gone" | "settled" | "loading";++/**+ * Schedules a detach for a table opened from the sidebar while the+ * "open tables in a detached window" setting is on (#13308). The tab's result+ * must be cached before the existing detach path accepts it, so the request+ * fires once the first load settles (result present and nothing executing),+ * or immediately when the tab already settled.+ */+export function requestDetachedTableOpen(+ getTab: () => QueryTab | undefined,+ dispatch: (detail: DetachTabRequestDetail) => void = (detail) => {+ window.dispatchEvent(new CustomEvent<DetachTabRequestDetail>(DETACH_TAB_REQUEST_EVENT, { detail }));+ },+): void {+ // Detached windows are desktop-only; the settings dialog also renders on+ // web, so the dispatch itself must be gated, not just the window opener.+ if (!isTauriRuntime()) return;+ // Tri-state, not boolean: a getter-watcher only re-runs its callback when the+ // value changes, so "loading" and "gone" must differ, or a load that ends+ // without a result followed by the tab closing would never stop the watcher.+ const settleState = (): DetachSettleState => {+ const tab = getTab();+ if (!tab) return "gone";+ if (!tab.isExecuting && !tab.isCancelling && tab.result !== undefined) return "settled";+ return "loading";+ };+ if (settleState() === "settled") {+ dispatch({ tabId: getTab()!.id });+ return;+ }+ const stop = watch(+ settleState,+ (state) => {+ // A load that errors without a result or a tab that closes before+ // settling must not leave the watcher alive forever.+ if (state === "loading") return;+ stop();+ if (state === "settled") dispatch({ tabId: getTab()!.id });+ },+ { flush: "post" },+ );+}diff --git a/apps/desktop/src/stores/settingsStore.ts b/apps/desktop/src/stores/settingsStore.tsindex 6406cb532d..be59c38186 100644--- a/apps/desktop/src/stores/settingsStore.ts+++ b/apps/desktop/src/stores/settingsStore.ts@@ -1200,6 +1200,7 @@ export interface EditorSettings {deepLinkConnectionConfirmMode: DeepLinkConnectionConfirmMode;dataTabReuseMode: DataTabReuseMode;openDataTabsNextToActive: boolean;+ openTablesInDetachedWindow: boolean;prefillNewQueryWithSelect: boolean;generateSqlIncludeDatabaseName: boolean;generateSqlQuoteIdentifiers: boolean;@@ -1557,6 +1558,7 @@ export const DEFAULT_EDITOR_SETTINGS: EditorSettings = {deepLinkConnectionConfirmMode: "always",dataTabReuseMode: DEFAULT_DATA_TAB_REUSE_MODE,openDataTabsNextToActive: false,+ openTablesInDetachedWindow: false,prefillNewQueryWithSelect: true,generateSqlIncludeDatabaseName: false,generateSqlQuoteIdentifiers: true,@@ -2294,6 +2296,7 @@ export function normalizeEditorSettings(settings: Partial<EditorSettings>, exist).reuseDataTab,),openDataTabsNextToActive: typeof settings.openDataTabsNextToActive === "boolean" ? settings.openDataTabsNextToActive : DEFAULT_EDITOR_SETTINGS.openDataTabsNextToActive,+ openTablesInDetachedWindow: typeof settings.openTablesInDetachedWindow === "boolean" ? settings.openTablesInDetachedWindow : DEFAULT_EDITOR_SETTINGS.openTablesInDetachedWindow,prefillNewQueryWithSelect: typeof settings.prefillNewQueryWithSelect === "boolean" ? settings.prefillNewQueryWithSelect : DEFAULT_EDITOR_SETTINGS.prefillNewQueryWithSelect,generateSqlIncludeDatabaseName: settings.generateSqlIncludeDatabaseName === true,generateSqlQuoteIdentifiers: typeof settings.generateSqlQuoteIdentifiers === "boolean" ? settings.generateSqlQuoteIdentifiers : DEFAULT_EDITOR_SETTINGS.generateSqlQuoteIdentifiers,@@ -3204,6 +3207,7 @@ export const useSettingsStore = defineStore("settings", () => {if (partial.deepLinkConnectionConfirmMode !== undefined) editorSettings.value.deepLinkConnectionConfirmMode = normalizeDeepLinkConnectionConfirmMode(partial.deepLinkConnectionConfirmMode);if (partial.dataTabReuseMode !== undefined) editorSettings.value.dataTabReuseMode = normalizeDataTabReuseMode(partial.dataTabReuseMode);if (partial.openDataTabsNextToActive !== undefined) editorSettings.value.openDataTabsNextToActive = partial.openDataTabsNextToActive === true;+ if (partial.openTablesInDetachedWindow !== undefined) editorSettings.value.openTablesInDetachedWindow = partial.openTablesInDetachedWindow === true;if (partial.prefillNewQueryWithSelect !== undefined) editorSettings.value.prefillNewQueryWithSelect = partial.prefillNewQueryWithSelect;if (partial.generateSqlIncludeDatabaseName !== undefined) editorSettings.value.generateSqlIncludeDatabaseName = partial.generateSqlIncludeDatabaseName === true;if (partial.generateSqlQuoteIdentifiers !== undefined) editorSettings.value.generateSqlQuoteIdentifiers = partial.generateSqlQuoteIdentifiers === true;