Skip to content

armgit / dbx

Public Imported from GitHub
0

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。

feat(tabs): reopen closed tabs with shortcut and context menu

lxk9552c6e0c8145b9
diff --git a/apps/desktop/src/App.vue b/apps/desktop/src/App.vue
index 1d28942995..e4ae592c5f 100644
--- a/apps/desktop/src/App.vue
+++ b/apps/desktop/src/App.vue
@@ -120,6 +120,7 @@ import {
isCloseAllTabsShortcut,
isCloseOtherTabsShortcut,
isCloseTabShortcut,
+ isReopenClosedTabShortcut,
isCloseWindowShortcut,
isDisconnectAllActiveConnectionsShortcut,
isEditTableStructureShortcut,
@@ -4425,6 +4426,12 @@ async function handleKeydown(e: KeyboardEvent) {
await closeActiveSurface();
return;
}
+ if (isReopenClosedTabShortcut(e, shortcuts)) {
+ e.preventDefault();
+ e.stopPropagation();
+ queryStore.reopenClosedTab();
+ return;
+ }
if (isSaveShortcut(e, shortcuts) && e.target instanceof Element && isObjectSourceSaveShortcutTarget(e.target)) {
return;
}
diff --git a/apps/desktop/src/components/layout/EditorGroupTabBar.vue b/apps/desktop/src/components/layout/EditorGroupTabBar.vue
index 1ff5bf56f6..55cbb46e7f 100644
--- a/apps/desktop/src/components/layout/EditorGroupTabBar.vue
+++ b/apps/desktop/src/components/layout/EditorGroupTabBar.vue
@@ -89,7 +89,8 @@ import { hexToRgba } from "@/lib/common/color";
import { copyToClipboard } from "@/lib/common/clipboard";
import { redisDatabaseLabel } from "@/lib/redis/redisDatabaseAlias";
import { parseTabDragPayload, serializeTabDragPayload } from "@/lib/tabs/tabDrag";
-import { createCloseAllTabMenuItem, createCloseLeftTabMenuItem, createCloseOtherTabMenuItem, createCloseRightTabMenuItem, createCloseTabMenuItem, createLocateTabMenuItem, createPinTabMenuItem, createRenameDuplicateTabItems } from "@/lib/tabs/tabMenu";
+import { createCloseAllTabMenuItem, createCloseLeftTabMenuItem, createCloseOtherTabMenuItem, createCloseRightTabMenuItem, createCloseTabMenuItem, createLocateTabMenuItem, createPinTabMenuItem, createRenameDuplicateTabItems, createReopenClosedTabMenuItem } from "@/lib/tabs/tabMenu";
+import { formatShortcut } from "@/lib/editor/shortcutRegistry";
import { findTabWithSameTitleSuffix, joinTabTitleParts, TAB_TITLE_SUFFIX_MAX_LENGTH, tabConnectionColor, dirtyTabTitleStyle, tabColorStyle as sharedTabColorStyle, tabDatabaseIconType, tabDisplayTitle, tabDisplayTitleParts, tabIconClass, tabTooltipLines } from "@/lib/tabs/tabPresentation";
import { activeTabSidebarTarget } from "@/lib/sidebar/sidebarActiveTabTarget";
import "./appTabBar.css";
@@ -1508,6 +1509,12 @@ function getTabMenuItems(tab: QueryTab): ContextMenuItem[] {
label: t("contextMenu.closeTab"),
onClose: () => closeTab(tab),
}),
+ createReopenClosedTabMenuItem({
+ label: t("contextMenu.reopenClosedTab"),
+ disabled: !queryStore.canReopenClosedTab,
+ shortcut: formatShortcut(settingsStore.editorSettings.shortcuts?.reopenClosedTab ?? "Shift+Mod+T"),
+ onReopen: () => queryStore.reopenClosedTab(),
+ }),
];
return items;
}
diff --git a/apps/desktop/src/components/layout/__tests__/EditorGroupTabBar.behavior.spec.ts b/apps/desktop/src/components/layout/__tests__/EditorGroupTabBar.behavior.spec.ts
index 271097c4d0..15506fe351 100644
--- a/apps/desktop/src/components/layout/__tests__/EditorGroupTabBar.behavior.spec.ts
+++ b/apps/desktop/src/components/layout/__tests__/EditorGroupTabBar.behavior.spec.ts
@@ -105,6 +105,7 @@ function mountBar(
duplicateTab: "Duplicate",
copyName: "Copy name",
closeTab: "Close",
+ reopenClosedTab: "Reopen closed tab",
closeOtherTabs: "Close other tabs",
closeLeftTabs: "Close left tabs",
closeRightTabs: "Close right tabs",
diff --git a/apps/desktop/src/components/layout/__tests__/EditorGroupTabBar.groups.spec.ts b/apps/desktop/src/components/layout/__tests__/EditorGroupTabBar.groups.spec.ts
index 8ab0c397c0..21588985a3 100644
--- a/apps/desktop/src/components/layout/__tests__/EditorGroupTabBar.groups.spec.ts
+++ b/apps/desktop/src/components/layout/__tests__/EditorGroupTabBar.groups.spec.ts
@@ -68,6 +68,7 @@ function mountBar(groupId: string, tabs: ReturnType<ReturnType<typeof useQuerySt
duplicateTab: "Duplicate",
copyName: "Copy name",
closeTab: "Close",
+ reopenClosedTab: "Reopen closed tab",
closeOtherTabs: "Close other tabs",
closeLeftTabs: "Close left tabs",
closeRightTabs: "Close right tabs",
diff --git a/apps/desktop/src/i18n/__tests__/featureMessages.spec.ts b/apps/desktop/src/i18n/__tests__/featureMessages.spec.ts
index b21f19641e..e236b93110 100644
--- a/apps/desktop/src/i18n/__tests__/featureMessages.spec.ts
+++ b/apps/desktop/src/i18n/__tests__/featureMessages.spec.ts
@@ -52,7 +52,26 @@ const FEATURE_MESSAGES: FeatureMessages[] = [
{ feature: "quick open", keys: ["quickOpen.*", "settings.shortcutGlobalSearch"] },
{
feature: "editor tab context menu",
- keys: under("contextMenu", ["changeOrientation", "closeAllTabs", "closeLeftTabs", "closeOtherTabs", "closeRightTabs", "closeTab", "closeTabGroup", "compactTabTitle", "copyName", "editTabGroup", "fullTabTitle", "pinTab", "resetTabGroup", "splitDown", "splitRight", "unpinTab", "unsplit"]),
+ keys: under("contextMenu", [
+ "changeOrientation",
+ "closeAllTabs",
+ "closeLeftTabs",
+ "closeOtherTabs",
+ "closeRightTabs",
+ "closeTab",
+ "closeTabGroup",
+ "compactTabTitle",
+ "copyName",
+ "editTabGroup",
+ "fullTabTitle",
+ "pinTab",
+ "reopenClosedTab",
+ "resetTabGroup",
+ "splitDown",
+ "splitRight",
+ "unpinTab",
+ "unsplit",
+ ]),
},
{ feature: "offline Agent export", keys: ["driverStore.offlineExport*"] },
{ feature: "offline Agent import", keys: ["driverStore.offlineImport*", "driverStore.offlineJreImport*"] },
diff --git a/apps/desktop/src/i18n/locales/az.ts b/apps/desktop/src/i18n/locales/az.ts
index 019e0d8d1d..f9a774ded1 100644
--- a/apps/desktop/src/i18n/locales/az.ts
+++ b/apps/desktop/src/i18n/locales/az.ts
@@ -3563,6 +3563,7 @@ export default withEnglishFallback({
compactTabTitle: "Vərəq başlıqlarını qısalt",
fullTabTitle: "Vərəq başlıqlarını tam göstər",
closeTab: "Vərəqi bağla",
+ reopenClosedTab: "Bağlanmış vərəqi yenidən aç",
editTabGroup: "Vərəq qrupunu redaktə et",
resetTabGroup: "Vərəq qrupunu sıfırla",
closeTabGroup: "Vərəq qrupunu bağla",
@@ -8053,6 +8054,7 @@ export default withEnglishFallback({
shortcutNewQuery: "Yeni sorğu",
shortcutOpenSettings: "Parametrləri aç",
shortcutCloseTab: "Vərəqi bağla",
+ shortcutReopenClosedTab: "Bağlanmış vərəqi yenidən aç",
shortcutCloseWindow: "Pəncərəni bağla",
shortcutFocusSearch: "Cari görünüşün axtarış sahəsinə keç",
shortcutQuickOpen: "Sürətli açılış (bütün verilənlər bazası obyektlərini axtar)",
diff --git a/apps/desktop/src/i18n/locales/en.ts b/apps/desktop/src/i18n/locales/en.ts
index cf87bb9658..d9b7f436f9 100644
--- a/apps/desktop/src/i18n/locales/en.ts
+++ b/apps/desktop/src/i18n/locales/en.ts
@@ -4105,6 +4105,7 @@ export default {
compactTabTitle: "Shorten Tab Titles",
fullTabTitle: "Show Full Tab Titles",
closeTab: "Close Tab",
+ reopenClosedTab: "Reopen Closed Tab",
editTabGroup: "Edit Tab Group",
resetTabGroup: "Reset Tab Group",
closeTabGroup: "Close Tab Group",
@@ -9184,6 +9185,7 @@ export default {
shortcutNewQuery: "New query",
shortcutOpenSettings: "Open settings",
shortcutCloseTab: "Close tab",
+ shortcutReopenClosedTab: "Reopen closed tab",
shortcutCloseWindow: "Close window",
shortcutFocusSearch: "Focus current view search",
shortcutQuickOpen: "Quick open (search all database objects)",
diff --git a/apps/desktop/src/i18n/locales/es.ts b/apps/desktop/src/i18n/locales/es.ts
index 0c9a5e66c6..16188689d8 100644
--- a/apps/desktop/src/i18n/locales/es.ts
+++ b/apps/desktop/src/i18n/locales/es.ts
@@ -4008,6 +4008,7 @@ export default withEnglishFallback({
compactTabTitle: "Acortar títulos de pestañas",
fullTabTitle: "Mostrar títulos completos de pestañas",
closeTab: "Cerrar pestaña",
+ reopenClosedTab: "Volver a abrir pestaña cerrada",
editTabGroup: "Editar grupo de pestañas",
resetTabGroup: "Restablecer grupo de pestañas",
closeTabGroup: "Cerrar grupo de pestañas",
@@ -8400,6 +8401,7 @@ export default withEnglishFallback({
shortcutNewQuery: "Nueva consulta",
shortcutOpenSettings: "Abrir configuración",
shortcutCloseTab: "Cerrar pestaña",
+ shortcutReopenClosedTab: "Volver a abrir pestaña cerrada",
shortcutCloseWindow: "Cerrar ventana",
shortcutToggleSidebar: "Alternar barra lateral",
shortcutToggleZenMode: "Alternar modo Zen",
diff --git a/apps/desktop/src/i18n/locales/id.ts b/apps/desktop/src/i18n/locales/id.ts
index 5ecb86cf95..e9c81190d6 100644
--- a/apps/desktop/src/i18n/locales/id.ts
+++ b/apps/desktop/src/i18n/locales/id.ts
@@ -3881,6 +3881,7 @@ export default withEnglishFallback({
compactTabTitle: "Persingkat Judul Tab",
fullTabTitle: "Tampilkan Judul Tab Lengkap",
closeTab: "Tutup Tab",
+ reopenClosedTab: "Buka kembali tab yang ditutup",
editTabGroup: "Edit Grup Tab",
resetTabGroup: "Atur Ulang Grup Tab",
closeTabGroup: "Tutup Grup Tab",
@@ -8865,6 +8866,7 @@ export default withEnglishFallback({
shortcutNewQuery: "Kueri baru",
shortcutOpenSettings: "Buka pengaturan",
shortcutCloseTab: "Tutup tab",
+ shortcutReopenClosedTab: "Buka kembali tab yang ditutup",
shortcutCloseWindow: "Tutup jendela",
shortcutFocusSearch: "Fokus pencarian tampilan saat ini",
shortcutQuickOpen: "Buka cepat (cari semua objek database)",
diff --git a/apps/desktop/src/i18n/locales/it.ts b/apps/desktop/src/i18n/locales/it.ts
index 9151e0b559..b816acb76d 100644
--- a/apps/desktop/src/i18n/locales/it.ts
+++ b/apps/desktop/src/i18n/locales/it.ts
@@ -3852,6 +3852,7 @@ export default withEnglishFallback({
compactTabTitle: "Accorcia Titoli Schede",
fullTabTitle: "Mostra titoli completi delle schede",
closeTab: "Chiudi Scheda",
+ reopenClosedTab: "Riapri scheda chiusa",
editTabGroup: "Modifica gruppo di schede",
resetTabGroup: "Ripristina gruppo di schede",
closeTabGroup: "Chiudi Gruppo di Schede",
@@ -8163,6 +8164,7 @@ export default withEnglishFallback({
shortcutNewQuery: "Nuova query",
shortcutOpenSettings: "Apri impostazioni",
shortcutCloseTab: "Chiudi scheda",
+ shortcutReopenClosedTab: "Riapri scheda chiusa",
shortcutCloseWindow: "Chiudi finestra",
shortcutFocusSearch: "Focalizza la ricerca nella vista corrente",
shortcutQuickOpen: "Apertura rapida (ricerca tutti gli oggetti del database)",
diff --git a/apps/desktop/src/i18n/locales/ja.ts b/apps/desktop/src/i18n/locales/ja.ts
index 86a5c7569b..a93089743a 100644
--- a/apps/desktop/src/i18n/locales/ja.ts
+++ b/apps/desktop/src/i18n/locales/ja.ts
@@ -3873,6 +3873,7 @@ export default withEnglishFallback({
compactTabTitle: "タブタイトルを短縮",
fullTabTitle: "タブの完全なタイトルを表示",
closeTab: "タブを閉じる",
+ reopenClosedTab: "閉じたタブを再度開く",
editTabGroup: "タブグループを編集",
resetTabGroup: "タブグループをリセット",
closeTabGroup: "このグループのタブを閉じる",
@@ -8152,6 +8153,7 @@ export default withEnglishFallback({
shortcutNewQuery: "新しいクエリ",
shortcutOpenSettings: "設定を開く",
shortcutCloseTab: "タブを閉じる",
+ shortcutReopenClosedTab: "閉じたタブを再度開く",
shortcutCloseWindow: "ウィンドウを閉じる",
shortcutFocusSearch: "現在のビューの検索にフォーカス",
shortcutQuickOpen: "クイックオープン (すべてのデータベースオブジェクトを検索)",
diff --git a/apps/desktop/src/i18n/locales/ko.ts b/apps/desktop/src/i18n/locales/ko.ts
index ccab4c7900..d44529d933 100644
--- a/apps/desktop/src/i18n/locales/ko.ts
+++ b/apps/desktop/src/i18n/locales/ko.ts
@@ -3800,6 +3800,7 @@ export default withEnglishFallback({
compactTabTitle: "탭 제목 줄이기",
fullTabTitle: "전체 탭 제목 표시",
closeTab: "탭 닫기",
+ reopenClosedTab: "닫은 탭 다시 열기",
editTabGroup: "탭 그룹 편집",
resetTabGroup: "탭 그룹 초기화",
closeTabGroup: "이 그룹의 탭 닫기",
@@ -8034,6 +8035,7 @@ export default withEnglishFallback({
shortcutNewQuery: "새 쿼리",
shortcutOpenSettings: "설정 열기",
shortcutCloseTab: "탭 닫기",
+ shortcutReopenClosedTab: "닫은 탭 다시 열기",
shortcutCloseWindow: "창 닫기",
shortcutFocusSearch: "현재 화면 검색에 포커스",
shortcutQuickOpen: "빠른 열기 (모든 데이터베이스 객체 검색)",
diff --git a/apps/desktop/src/i18n/locales/pt-BR.ts b/apps/desktop/src/i18n/locales/pt-BR.ts
index d942fda8c3..adb1b21c70 100644
--- a/apps/desktop/src/i18n/locales/pt-BR.ts
+++ b/apps/desktop/src/i18n/locales/pt-BR.ts
@@ -3852,6 +3852,7 @@ export default withEnglishFallback({
compactTabTitle: "Encurtar Títulos das Abas",
fullTabTitle: "Mostrar títulos completos das abas",
closeTab: "Fechar Aba",
+ reopenClosedTab: "Reabrir aba fechada",
editTabGroup: "Editar grupo de abas",
resetTabGroup: "Redefinir grupo de abas",
closeTabGroup: "Fechar Grupo de Abas",
@@ -8161,6 +8162,7 @@ export default withEnglishFallback({
shortcutNewQuery: "Nova consulta",
shortcutOpenSettings: "Abrir configurações",
shortcutCloseTab: "Fechar aba",
+ shortcutReopenClosedTab: "Reabrir aba fechada",
shortcutCloseWindow: "Fechar janela",
shortcutToggleSidebar: "Alternar barra lateral",
shortcutToggleZenMode: "Alternar modo Zen",
diff --git a/apps/desktop/src/i18n/locales/ru.ts b/apps/desktop/src/i18n/locales/ru.ts
index e42b4eb0fd..c67568c819 100644
--- a/apps/desktop/src/i18n/locales/ru.ts
+++ b/apps/desktop/src/i18n/locales/ru.ts
@@ -3960,6 +3960,7 @@ export default withEnglishFallback({
compactTabTitle: "Сократить заголовки вкладок",
fullTabTitle: "Показывать полные заголовки вкладок",
closeTab: "Закрыть вкладку",
+ reopenClosedTab: "Заново открыть закрытую вкладку",
editTabGroup: "Изменить группу вкладок",
resetTabGroup: "Сбросить группу вкладок",
closeTabGroup: "Закрыть группу вкладок",
@@ -9518,6 +9519,7 @@ export default withEnglishFallback({
shortcutNewQuery: "Новый запрос",
shortcutOpenSettings: "Открыть настройки",
shortcutCloseTab: "Закрыть вкладку",
+ shortcutReopenClosedTab: "Заново открыть закрытую вкладку",
shortcutCloseWindow: "Закрыть окно",
shortcutFocusSearch: "Фокус на поиске в текущем представлении",
shortcutQuickOpen: "Быстрое открытие (поиск по всем объектам базы данных)",
diff --git a/apps/desktop/src/i18n/locales/tr.ts b/apps/desktop/src/i18n/locales/tr.ts
index d89fc48dca..3a5dcad211 100644
--- a/apps/desktop/src/i18n/locales/tr.ts
+++ b/apps/desktop/src/i18n/locales/tr.ts
@@ -3534,6 +3534,7 @@ export default withEnglishFallback({
compactTabTitle: "Sekme Başlıklarını Kısalt",
fullTabTitle: "Tam Sekme Başlıklarını Göster",
closeTab: "Sekmeyi Kapat",
+ reopenClosedTab: "Kapatılan sekmeyi yeniden aç",
editTabGroup: "Sekme Grubunu Düzenle",
resetTabGroup: "Sekme Grubunu Sıfırla",
closeTabGroup: "Sekme Grubunu Kapat",
@@ -7954,6 +7955,7 @@ export default withEnglishFallback({
shortcutNewQuery: "Yeni sorgu",
shortcutOpenSettings: "Ayarları aç",
shortcutCloseTab: "Sekmeyi kapat",
+ shortcutReopenClosedTab: "Kapatılan sekmeyi yeniden aç",
shortcutCloseWindow: "Pencereyi kapat",
shortcutFocusSearch: "Geçerli görünüm aramasına odaklan",
shortcutQuickOpen: "Hızlı aç (tüm veritabanı nesnelerinde ara)",
diff --git a/apps/desktop/src/i18n/locales/zh-CN.ts b/apps/desktop/src/i18n/locales/zh-CN.ts
index 562b2d713f..ca11d7ce56 100644
--- a/apps/desktop/src/i18n/locales/zh-CN.ts
+++ b/apps/desktop/src/i18n/locales/zh-CN.ts
@@ -4036,6 +4036,7 @@ export default withEnglishFallback({
compactTabTitle: "缩短标签标题",
fullTabTitle: "完整标签标题",
closeTab: "关闭标签页",
+ reopenClosedTab: "重新打开关闭的标签页",
editTabGroup: "编辑标签分组",
resetTabGroup: "恢复默认分组",
closeTabGroup: "关闭本组标签页",
@@ -9168,6 +9169,7 @@ export default withEnglishFallback({
shortcutNewQuery: "新建查询",
shortcutOpenSettings: "打开设置",
shortcutCloseTab: "关闭标签页",
+ shortcutReopenClosedTab: "重新打开关闭的标签页",
shortcutCloseWindow: "关闭窗口",
shortcutToggleSidebar: "切换侧边栏",
shortcutToggleZenMode: "切换禅模式",
diff --git a/apps/desktop/src/i18n/locales/zh-TW.ts b/apps/desktop/src/i18n/locales/zh-TW.ts
index 7401f1ef17..aa6ad21706 100644
--- a/apps/desktop/src/i18n/locales/zh-TW.ts
+++ b/apps/desktop/src/i18n/locales/zh-TW.ts
@@ -3853,6 +3853,7 @@ export default withEnglishFallback({
compactTabTitle: "縮短標籤標題",
fullTabTitle: "完整分頁標題",
closeTab: "關閉分頁",
+ reopenClosedTab: "重新開啟關閉的分頁",
editTabGroup: "編輯分頁群組",
resetTabGroup: "重設分頁群組",
closeTabGroup: "關閉本群組分頁",
@@ -7472,6 +7473,7 @@ export default withEnglishFallback({
shortcutNewQuery: "建立查詢",
shortcutOpenSettings: "開啟設定",
shortcutCloseTab: "關閉分頁",
+ shortcutReopenClosedTab: "重新開啟關閉的分頁",
shortcutCloseWindow: "關閉視窗",
shortcutToggleSidebar: "切換側邊欄",
shortcutToggleZenMode: "切換禪模式",
diff --git a/apps/desktop/src/lib/__tests__/editor/shortcutRegistry.spec.ts b/apps/desktop/src/lib/__tests__/editor/shortcutRegistry.spec.ts
index 4eeed38d79..3af9c55cab 100644
--- a/apps/desktop/src/lib/__tests__/editor/shortcutRegistry.spec.ts
+++ b/apps/desktop/src/lib/__tests__/editor/shortcutRegistry.spec.ts
@@ -278,6 +278,20 @@ describe("shortcutRegistry editor actions", () => {
expect(normalizeShortcutSettings({ closeTab: "" }).closeTab).toBe("");
});
+ it("registers reopenClosedTab as a global shortcut with Shift+Mod+T default", () => {
+ const definition = SHORTCUT_DEFINITIONS.find((item) => item.id === "reopenClosedTab");
+ expect(definition).toMatchObject({
+ id: "reopenClosedTab",
+ labelKey: "settings.shortcutReopenClosedTab",
+ scope: "global",
+ defaultShortcut: "Shift+Mod+T",
+ });
+ expect(DEFAULT_SHORTCUT_SETTINGS.reopenClosedTab).toBe("Shift+Mod+T");
+ expect(formatShortcut(DEFAULT_SHORTCUT_SETTINGS.reopenClosedTab, "Win32")).toBe("Ctrl+Shift+T");
+ expect(formatShortcut(DEFAULT_SHORTCUT_SETTINGS.reopenClosedTab, "MacIntel")).toBe("Shift+Cmd+T");
+ expect(findShortcutConflict("reopenClosedTab", DEFAULT_SHORTCUT_SETTINGS.reopenClosedTab, DEFAULT_SHORTCUT_SETTINGS)).toBeNull();
+ });
+
it("registers closeWindow as a global shortcut with Shift+Mod+W default", () => {
const definition = SHORTCUT_DEFINITIONS.find((item) => item.id === "closeWindow");
expect(definition).toMatchObject({
diff --git a/apps/desktop/src/lib/editor/keyboardShortcuts.ts b/apps/desktop/src/lib/editor/keyboardShortcuts.ts
index 121d3c32c3..10f5eac357 100644
--- a/apps/desktop/src/lib/editor/keyboardShortcuts.ts
+++ b/apps/desktop/src/lib/editor/keyboardShortcuts.ts
@@ -184,6 +184,10 @@ export function isCloseTabShortcut(event: ShortcutLikeEvent, shortcuts?: Partial
return matchesShortcut(event, actionShortcut("closeTab", shortcuts));
}
+export function isReopenClosedTabShortcut(event: ShortcutLikeEvent, shortcuts?: Partial<ShortcutSettings>): boolean {
+ return matchesShortcut(event, actionShortcut("reopenClosedTab", shortcuts));
+}
+
export function isCloseOtherTabsShortcut(event: ShortcutLikeEvent, shortcuts?: Partial<ShortcutSettings>, platform = globalThis.navigator?.platform || ""): boolean {
return matchesShortcut(event, actionShortcut("closeOtherTabs", shortcuts), platform);
}
diff --git a/apps/desktop/src/lib/editor/shortcutRegistry.ts b/apps/desktop/src/lib/editor/shortcutRegistry.ts
index 16f13d9bdf..784026a7c1 100644
--- a/apps/desktop/src/lib/editor/shortcutRegistry.ts
+++ b/apps/desktop/src/lib/editor/shortcutRegistry.ts
@@ -53,6 +53,7 @@ export type ShortcutActionId =
| "newQuery"
| "openSettings"
| "closeTab"
+ | "reopenClosedTab"
| "closeOtherTabs"
| "closeAllTabs"
| "closeWindow"
@@ -486,6 +487,12 @@ export const SHORTCUT_DEFINITIONS: ShortcutDefinition[] = [
scope: "global",
defaultShortcut: "Mod+W",
},
+ {
+ id: "reopenClosedTab",
+ labelKey: "settings.shortcutReopenClosedTab",
+ scope: "global",
+ defaultShortcut: "Shift+Mod+T",
+ },
{
id: "closeOtherTabs",
labelKey: "contextMenu.closeOtherTabs",
diff --git a/apps/desktop/src/lib/tabs/tabMenu.ts b/apps/desktop/src/lib/tabs/tabMenu.ts
index 5f0f05ef16..696f12a316 100644
--- a/apps/desktop/src/lib/tabs/tabMenu.ts
+++ b/apps/desktop/src/lib/tabs/tabMenu.ts
@@ -1,4 +1,4 @@
-import { Copy, Crosshair, Pencil, Pin, X } from "@lucide/vue";
+import { Copy, Crosshair, Pencil, Pin, RotateCcw, X } from "@lucide/vue";
import type { ContextMenuItem } from "@/components/ui/customContextMenuRegistry";
import type { QueryTab } from "@/types/database";
@@ -44,6 +44,16 @@ export function createCloseTabMenuItem(options: { label: string; onClose: () =>
return { label: options.label, action: options.onClose, icon: X };
}
+export function createReopenClosedTabMenuItem(options: { label: string; disabled?: boolean; shortcut?: string; onReopen: () => void }): ContextMenuItem {
+ return {
+ label: options.label,
+ action: options.onReopen,
+ ...(options.disabled !== undefined ? { disabled: options.disabled } : {}),
+ ...(options.shortcut ? { shortcut: options.shortcut } : {}),
+ icon: RotateCcw,
+ };
+}
+
export function createCloseOtherTabMenuItem(options: { label: string; disabled?: boolean; shortcut?: string; onClose: () => void }): ContextMenuItem {
return {
label: options.label,
diff --git a/apps/desktop/src/stores/__tests__/queryStore.reopenClosedTab.spec.ts b/apps/desktop/src/stores/__tests__/queryStore.reopenClosedTab.spec.ts
new file mode 100644
index 0000000000..5eb61fe5f0
--- /dev/null
+++ b/apps/desktop/src/stores/__tests__/queryStore.reopenClosedTab.spec.ts
@@ -0,0 +1,131 @@
+import { createPinia, setActivePinia } from "pinia";
+import { beforeEach, describe, expect, it, vi } from "vitest";
+
+describe("queryStore reopenClosedTab", () => {
+ beforeEach(() => {
+ vi.resetModules();
+ vi.unstubAllGlobals();
+ vi.stubGlobal("localStorage", {
+ getItem: vi.fn(() => null),
+ setItem: vi.fn(),
+ removeItem: vi.fn(),
+ });
+ vi.stubGlobal("window", {
+ dispatchEvent: vi.fn(),
+ setTimeout: vi.fn((_fn: () => void) => 0),
+ clearTimeout: vi.fn(),
+ });
+ setActivePinia(createPinia());
+ });
+
+ it("reopens a recently closed query tab with its SQL, database, and position preserved", async () => {
+ const { useQueryStore } = await import("@/stores/queryStore");
+ const store = useQueryStore();
+ const tabId = store.createTab("pg-1", "app", "Query 1", "query");
+ const tab = store.tabs.find((t) => t.id === tabId)!;
+ tab.sql = "SELECT * FROM users WHERE active = true";
+
+ expect(store.canReopenClosedTab).toBe(false);
+
+ store.closeTab(tabId, { force: true });
+ expect(store.tabs.find((t) => t.id === tabId)).toBeUndefined();
+ expect(store.canReopenClosedTab).toBe(true);
+
+ const reopenedId = store.reopenClosedTab();
+ expect(reopenedId).toBeTruthy();
+ expect(store.canReopenClosedTab).toBe(false);
+
+ const reopenedTab = store.tabs.find((t) => t.id === reopenedId);
+ expect(reopenedTab).toBeDefined();
+ expect(reopenedTab?.title).toBe("Query 1");
+ expect(reopenedTab?.connectionId).toBe("pg-1");
+ expect(reopenedTab?.database).toBe("app");
+ expect(reopenedTab?.sql).toBe("SELECT * FROM users WHERE active = true");
+ expect(store.activeTabId).toBe(reopenedId);
+ });
+
+ it("reopens multiple closed tabs in LIFO order", async () => {
+ const { useQueryStore } = await import("@/stores/queryStore");
+ const store = useQueryStore();
+ store.createTab("pg-1", "app", "Query 1", "query");
+ const id2 = store.createTab("pg-1", "app", "Query 2", "query");
+ const id3 = store.createTab("pg-1", "app", "Query 3", "query");
+
+ store.closeTab(id2);
+ store.closeTab(id3);
+
+ expect(store.closedTabsHistory.length).toBe(2);
+
+ // LIFO: most recently closed (id3) is reopened first
+ const reopenedIdFirst = store.reopenClosedTab();
+ const tabFirst = store.tabs.find((t) => t.id === reopenedIdFirst);
+ expect(tabFirst?.title).toBe("Query 3");
+
+ // Next is id2
+ const reopenedIdSecond = store.reopenClosedTab();
+ const tabSecond = store.tabs.find((t) => t.id === reopenedIdSecond);
+ expect(tabSecond?.title).toBe("Query 2");
+
+ expect(store.canReopenClosedTab).toBe(false);
+ expect(store.reopenClosedTab()).toBeNull();
+ });
+
+ it("returns null when closed tabs history is empty", async () => {
+ const { useQueryStore } = await import("@/stores/queryStore");
+ const store = useQueryStore();
+ expect(store.canReopenClosedTab).toBe(false);
+ expect(store.reopenClosedTab()).toBeNull();
+ });
+
+ it("clears closed tabs history on clearClosedTabsHistory", async () => {
+ const { useQueryStore } = await import("@/stores/queryStore");
+ const store = useQueryStore();
+ const id = store.createTab("pg-1", "app", "Query 1", "query");
+ store.closeTab(id);
+ expect(store.canReopenClosedTab).toBe(true);
+
+ store.clearClosedTabsHistory();
+ expect(store.canReopenClosedTab).toBe(false);
+ expect(store.reopenClosedTab()).toBeNull();
+ });
+
+ it("reopens tab into focused group if original group was pruned", async () => {
+ const { useQueryStore } = await import("@/stores/queryStore");
+ const store = useQueryStore();
+ store.createTab("pg-1", "app", "Query 1", "query");
+ const id2 = store.createTab("pg-1", "app", "Query 2", "query");
+
+ expect(store.splitTabDown(id2)).toBe(true);
+ expect(store.groups.length).toBe(2);
+
+ // Closing id2 leaves the second group empty, so it gets pruned
+ store.closeTab(id2);
+ expect(store.groups.length).toBe(1);
+
+ // Reopening id2 falls back to the remaining group
+ const reopenedId = store.reopenClosedTab();
+ expect(reopenedId).toBeTruthy();
+ expect(store.groups[0].tabIds).toContain(reopenedId);
+ expect(store.activeTabId).toBe(reopenedId);
+ });
+
+ it("respects pinned tab boundaries when reopening an unpinned tab", async () => {
+ const { useQueryStore } = await import("@/stores/queryStore");
+ const store = useQueryStore();
+ const pinnedId = store.createTab("pg-1", "app", "Pinned Query", "query");
+ const pinnedTab = store.tabs.find((t) => t.id === pinnedId)!;
+ pinnedTab.pinned = true;
+
+ const unpinnedId = store.createTab("pg-1", "app", "Regular Query", "query");
+ store.closeTab(unpinnedId);
+
+ const reopenedId = store.reopenClosedTab();
+ expect(reopenedId).toBeTruthy();
+
+ const group = store.groups[0];
+ const pinnedIndex = group.tabIds.indexOf(pinnedId);
+ const reopenedIndex = group.tabIds.indexOf(reopenedId!);
+ expect(pinnedIndex).toBe(0);
+ expect(reopenedIndex).toBeGreaterThan(pinnedIndex);
+ });
+});
diff --git a/apps/desktop/src/stores/queryStore.ts b/apps/desktop/src/stores/queryStore.ts
index 37bc4bdf1d..8889ddfb7f 100644
--- a/apps/desktop/src/stores/queryStore.ts
+++ b/apps/desktop/src/stores/queryStore.ts
@@ -209,6 +209,48 @@ function cloneTabDraft<T>(value: T): T {
return JSON.parse(JSON.stringify(value)) as T;
}
+export interface ClosedTabHistoryEntry {
+ tab: QueryTab;
+ groupId?: string;
+ indexInGroup?: number;
+}
+
+function snapshotClosedTab(tab: QueryTab): QueryTab {
+ return {
+ ...tab,
+ isExecuting: false,
+ isCancelling: false,
+ queryExecutionStartedAt: undefined,
+ executionId: undefined,
+ executingResultRunId: undefined,
+ isExplaining: false,
+ explainExecutionId: undefined,
+ txnSessionId: undefined,
+ result: undefined,
+ results: undefined,
+ resultSessionId: undefined,
+ resultClientSessionId: undefined,
+ sourceLoad: undefined,
+ activeResultIndex: undefined,
+ resultRuns: undefined,
+ activeResultRunId: undefined,
+ structureDraft: tab.structureDraft ? cloneTabDraft(tab.structureDraft) : undefined,
+ tableMeta: tab.tableMeta
+ ? {
+ ...tab.tableMeta,
+ columns: [...tab.tableMeta.columns],
+ primaryKeys: [...tab.tableMeta.primaryKeys],
+ ...(tab.tableMeta.virtualPrimaryKeys ? { virtualPrimaryKeys: [...tab.tableMeta.virtualPrimaryKeys] } : {}),
+ }
+ : undefined,
+ objectBrowser: tab.objectBrowser ? { ...tab.objectBrowser } : undefined,
+ objectSource: tab.objectSource ? { ...tab.objectSource } : undefined,
+ editorViewport: tab.editorViewport ? { ...tab.editorViewport } : undefined,
+ editorSelection: tab.editorSelection ? { ...tab.editorSelection } : undefined,
+ uiState: tab.uiState ? cloneTabDraft(tab.uiState) : undefined,
+ };
+}
+
interface BuildQueryResultExportRequestOptions {
exportId: string;
filePath: string;
@@ -1135,6 +1177,24 @@ export const useQueryStore = defineStore("query", () => {
// Most-recently-activated tab ids, oldest first. Read-only view for the
// Ctrl+Tab switcher, which renders them in reverse.
const recentTabIds = computed(() => activeTabHistory.value);
+ const MAX_CLOSED_TABS_HISTORY = 30;
+ const closedTabsHistory = ref<ClosedTabHistoryEntry[]>([]);
+ const canReopenClosedTab = computed(() => closedTabsHistory.value.length > 0);
+
+ function clearClosedTabsHistory() {
+ closedTabsHistory.value = [];
+ }
+
+ function recordClosedTabHistory(tab: QueryTab, groupId?: string, indexInGroup?: number) {
+ closedTabsHistory.value.push({
+ tab: snapshotClosedTab(tab),
+ groupId,
+ indexInGroup,
+ });
+ if (closedTabsHistory.value.length > MAX_CLOSED_TABS_HISTORY) {
+ closedTabsHistory.value.shift();
+ }
+ }
function findGroup(groupId: string): EditorGroup | undefined {
return groups.value.find((group) => group.id === groupId);
@@ -4527,7 +4587,7 @@ export const useQueryStore = defineStore("query", () => {
}
}
- function closeTab(id: string, { force = false }: { force?: boolean } = {}) {
+ function closeTab(id: string, { force = false, skipHistory = false }: { force?: boolean; skipHistory?: boolean } = {}) {
const tab = tabs.value.find((t) => t.id === id);
if (!tab) return;
if (!force && shouldConfirmTabClose(tab)) {
@@ -4558,6 +4618,10 @@ export const useQueryStore = defineStore("query", () => {
const wasOwnerActive = owner?.activeTabId === id;
const wasGlobalActive = activeTabId.value === id;
+ if (!skipHistory) {
+ recordClosedTabHistory(tabs.value[idx], owner?.id, ownerIndexInGroup >= 0 ? ownerIndexInGroup : undefined);
+ }
+
tabs.value.splice(idx, 1);
releasePluginConnectionsAfterClose([tab]);
if (tab.externalSqlPath) refreshExternalSqlFileTitles();
@@ -4916,6 +4980,53 @@ export const useQueryStore = defineStore("query", () => {
if (newTab.mode === "data") void refreshDataTab(newId);
}
+ function reopenClosedTab(): string | null {
+ assertUpdateAllowsInteraction();
+ const entry = closedTabsHistory.value.pop();
+ if (!entry) return null;
+
+ const restoredTab = snapshotClosedTab(entry.tab);
+ if (tabs.value.some((t) => t.id === restoredTab.id)) {
+ restoredTab.id = uuid();
+ }
+
+ initializeResultAutoSave(restoredTab);
+
+ let targetGroup = entry.groupId ? groups.value.find((g) => g.id === entry.groupId) : undefined;
+ if (!targetGroup) {
+ targetGroup = focusedGroup() ?? groups.value[0];
+ }
+ if (!targetGroup) {
+ targetGroup = { id: "main", tabIds: [], activeTabId: null };
+ groups.value.push(targetGroup);
+ focusedGroupId.value = "main";
+ }
+
+ const pinnedCount = targetGroup.tabIds.filter((id) => tabs.value.find((item) => item.id === id)?.pinned).length;
+ let insertIndex = entry.indexInGroup !== undefined ? Math.max(0, Math.min(entry.indexInGroup, targetGroup.tabIds.length)) : targetGroup.tabIds.length;
+
+ if (restoredTab.pinned) {
+ insertIndex = Math.min(insertIndex, pinnedCount);
+ } else {
+ insertIndex = Math.max(insertIndex, pinnedCount);
+ }
+
+ targetGroup.tabIds.splice(insertIndex, 0, restoredTab.id);
+ tabs.value.push(restoredTab);
+
+ if (restoredTab.externalSqlPath) {
+ refreshExternalSqlFileTitles();
+ }
+
+ activateTab(restoredTab.id);
+
+ if (restoredTab.mode === "data") {
+ void refreshDataTab(restoredTab.id);
+ }
+
+ return restoredTab.id;
+ }
+
function closeTabsWhere(predicate: (tab: QueryTab) => boolean) {
const closingIds = new Set(tabs.value.filter((tab) => predicate(tab)).map((tab) => tab.id));
if (closingIds.size === 0) return;
@@ -10145,6 +10256,10 @@ export const useQueryStore = defineStore("query", () => {
closeFixedTabs,
closeAllTabs,
duplicateTab,
+ closedTabsHistory,
+ canReopenClosedTab,
+ reopenClosedTab,
+ clearClosedTabsHistory,
closeConnectionTabs,
closeDatabaseTabs,
closeDroppedTableObjectTabs,