fix(tabs): restore close-right tab action

This commit is contained in:
guoyongchang authored and GitHub committed 2026-08-05 02:59:19 +08:00
1 parent fb0aafa04b
commit eed0a26b6f
11 files changed
+228 -4

No files matched your search

@@ -184,6 +184,36 @@ function closeOtherRegularTabsFromTab(tab: QueryTab) {
closeSpecialRegularSurfaces();
}
function tabsToRightInGroup(tab: QueryTab) {
const groupedTabs = tab.pinned ? fixedTabs.value : regularTabs.value;
const targetIndex = groupedTabs.findIndex((item) => item.id === tab.id);
return targetIndex < 0 ? [] : groupedTabs.slice(targetIndex + 1);
}
function hasTabsToRight(tab: QueryTab) {
return tabsToRightInGroup(tab).length > 0 || (!tab.pinned && (!!props.settingsPageOpen || !!props.driverStoreOpen));
}
function closeTabsToRightFromTab(tab: QueryTab) {
const shouldActivateTarget = !tab.pinned && (!!props.settingsPageActive || !!props.driverStoreActive);
queryStore.closeRightTabs(tab.id, () => {
if (tab.pinned) return;
closeSpecialRegularSurfaces();
if (shouldActivateTarget) activateTab(tab.id);
});
}
function hasSpecialRegularSurfaceToRight(surface: SpecialRegularSurface) {
return surface === "settings" && !!props.driverStoreOpen;
}
function closeSpecialRegularSurfacesToRight(surface: SpecialRegularSurface) {
if (surface !== "settings" || !props.driverStoreOpen) return;
const shouldActivateSettings = !!props.driverStoreActive;
emit("close-driver-store");
if (shouldActivateSettings) emit("activate-settings-page");
}
function closeAllRegularSurfaces() {
queryStore.closeRegularTabs();
closeSpecialRegularSurfaces();
@@ -234,6 +264,12 @@ function getSpecialRegularTabMenuItems(surface: SpecialRegularSurface): ContextM
icon: X,
shortcut: settingsStore.editorSettings.shortcuts.closeOtherTabs,
},
{
label: t("contextMenu.closeRightTabs"),
action: () => closeSpecialRegularSurfacesToRight(surface),
disabled: !hasSpecialRegularSurfaceToRight(surface),
icon: X,
},
{
label: closeAllLabel,
action: closeAllRegularSurfaces,
@@ -297,6 +333,12 @@ function getTabMenuItems(tab: QueryTab): ContextMenuItem[] {
icon: X,
shortcut: settingsStore.editorSettings.shortcuts.closeOtherTabs,
},
{
label: t("contextMenu.closeRightTabs"),
action: () => closeTabsToRightFromTab(tab),
disabled: !hasTabsToRight(tab),
icon: X,
},
{
label: closeAllLabel,
action: closeAllAction,
@@ -35,3 +35,32 @@ describe("AppTabBar objects presentation", () => {
expect(tabBarSource.match(/tabMenuIcon\(tab\).*tabIconClass\(tab\)/g)).toHaveLength(2);
});
});
describe("AppTabBar right-side close action", () => {
it("places the action after close-other and disables it when the target has no tabs to its right", () => {
expect(tabBarSource).toContain('label: t("contextMenu.closeRightTabs")');
expect(tabBarSource).toContain("action: () => closeTabsToRightFromTab(tab)");
expect(tabBarSource).toContain("disabled: !hasTabsToRight(tab)");
const closeOtherPositions = [...tabBarSource.matchAll(/label: closeOtherLabel,/g)].map((match) => match.index);
const closeRightPositions = [...tabBarSource.matchAll(/label: t\("contextMenu\.closeRightTabs"\),/g)].map((match) => match.index);
const closeAllPositions = [...tabBarSource.matchAll(/label: closeAllLabel,/g)].map((match) => match.index);
expect(closeOtherPositions).toHaveLength(2);
expect(closeRightPositions).toHaveLength(2);
expect(closeAllPositions).toHaveLength(2);
closeRightPositions.forEach((position, index) => {
expect(position).toBeGreaterThan(closeOtherPositions[index]);
expect(position).toBeLessThan(closeAllPositions[index]);
});
});
it("waits for query tab confirmation before closing special surfaces", () => {
expect(tabBarSource).toMatch(/queryStore\.closeRightTabs\(tab\.id, \(\) => \{[\s\S]*closeSpecialRegularSurfaces\(\);/);
expect(tabBarSource).toContain("if (shouldActivateTarget) activateTab(tab.id)");
});
it("reactivates settings after closing an active driver store to its right", () => {
expect(tabBarSource).toContain("const shouldActivateSettings = !!props.driverStoreActive");
expect(tabBarSource).toMatch(/emit\("close-driver-store"\);\s*if \(shouldActivateSettings\) emit\("activate-settings-page"\);/);
});
});
+1
View File
@@ -2175,6 +2175,7 @@ export default {
fullTabTitle: "Show Full Tab Titles",
closeTab: "Close Tab",
closeFixedTab: "Close Fixed Tab",
closeRightTabs: "Close Tabs to the Right",
closeOtherTabs: "Close Other Tabs",
closeOtherRegularTabs: "Close Other Regular Tabs",
closeOtherFixedTabs: "Close Other Fixed Tabs",
+1
View File
@@ -2357,6 +2357,7 @@ export default withEnglishFallback({
createFunction: "Nueva función",
createTrigger: "Nuevo disparador",
changeOpenMode: "Modificar modo de apertura",
closeRightTabs: "Cerrar pestañas a la derecha",
},
visibleDatabases: {
title: "Bases de datos visibles",
+1
View File
@@ -2355,6 +2355,7 @@ export default withEnglishFallback({
createFunction: "Nuova funzione",
createTrigger: "Nuovo trigger",
changeOpenMode: "Modifica modalità apertura",
closeRightTabs: "Chiudi le schede a destra",
},
visibleDatabases: {
title: "Database Visibili",
+1
View File
@@ -2382,6 +2382,7 @@ export default withEnglishFallback({
createFunction: "新規関数",
createTrigger: "新規トリガー",
changeOpenMode: "開き方を変更",
closeRightTabs: "右側のタブを閉じる",
},
visibleDatabases: {
title: "表示するデータベース",
+1
View File
@@ -2357,6 +2357,7 @@ export default withEnglishFallback({
createFunction: "Nova função",
createTrigger: "Novo gatilho",
changeOpenMode: "Alterar modo de abertura",
closeRightTabs: "Fechar abas à direita",
},
visibleDatabases: {
title: "Bancos de dados visíveis",
+1
View File
@@ -2176,6 +2176,7 @@ export default withEnglishFallback({
fullTabTitle: "完整标签标题",
closeTab: "关闭标签页",
closeFixedTab: "关闭固定标签页",
closeRightTabs: "关闭右侧标签页",
closeOtherTabs: "关闭其他标签页",
closeOtherRegularTabs: "关闭其他普通标签页",
closeOtherFixedTabs: "关闭其他固定标签页",
+1
View File
@@ -2356,6 +2356,7 @@ export default withEnglishFallback({
createFunction: "新增函數",
createTrigger: "新增觸發器",
changeOpenMode: "修改開啟方式",
closeRightTabs: "關閉右側標籤頁",
},
visibleDatabases: {
title: "顯示資料庫",
+37 -4
View File
@@ -649,6 +649,7 @@ export const useQueryStore = defineStore("query", () => {
const pendingCloseTabId = ref<string | null>(null);
const pendingBatchCloseTabIds = ref<string[] | null>(null);
const pendingBatchCloseFinalActiveTabId = ref<string | null | undefined>(undefined);
let pendingBatchCloseComplete: (() => void) | null = null;
const isConfirmingAppClose = ref(false);
const closeConfirmContext = ref<CloseConfirmContext>("tab");
const tableStructureRefreshVersions = ref<Record<string, number>>({});
@@ -1903,11 +1904,14 @@ export const useQueryStore = defineStore("query", () => {
function finishPendingBatchClose() {
const finalActiveTabId = pendingBatchCloseFinalActiveTabId.value;
const onComplete = pendingBatchCloseComplete;
pendingBatchCloseTabIds.value = null;
pendingBatchCloseFinalActiveTabId.value = undefined;
pendingBatchCloseComplete = null;
if (finalActiveTabId !== undefined) {
activeTabId.value = finalActiveTabId && tabs.value.some((tab) => tab.id === finalActiveTabId) ? finalActiveTabId : null;
}
return onComplete;
}
function continuePendingBatchClose() {
@@ -1917,7 +1921,7 @@ export const useQueryStore = defineStore("query", () => {
const remainingIds = pendingIds.filter((id) => tabs.value.some((tab) => tab.id === id));
pendingBatchCloseTabIds.value = remainingIds;
if (remainingIds.length === 0) {
finishPendingBatchClose();
finishPendingBatchClose()?.();
return;
}
@@ -1928,15 +1932,20 @@ export const useQueryStore = defineStore("query", () => {
return;
}
finishPendingBatchClose();
const onComplete = finishPendingBatchClose();
for (const id of remainingIds) closeTab(id, { force: true });
onComplete?.();
}
function beginBatchClose(ids: string[], finalActiveTabId?: string | null) {
function beginBatchClose(ids: string[], finalActiveTabId?: string | null, onComplete?: () => void) {
const uniqueIds = [...new Set(ids)].filter((id) => tabs.value.some((tab) => tab.id === id));
if (uniqueIds.length === 0) return;
if (uniqueIds.length === 0) {
onComplete?.();
return;
}
pendingBatchCloseTabIds.value = uniqueIds;
pendingBatchCloseFinalActiveTabId.value = finalActiveTabId;
pendingBatchCloseComplete = onComplete ?? null;
continuePendingBatchClose();
}
@@ -1998,12 +2007,14 @@ export const useQueryStore = defineStore("query", () => {
const pendingId = pendingCloseTabId.value;
const batchIds = pendingBatchCloseTabIds.value?.filter((id) => tabs.value.some((tab) => tab.id === id)) ?? null;
const finalActiveTabId = pendingBatchCloseFinalActiveTabId.value;
const onBatchComplete = pendingBatchCloseComplete;
const confirmingAppClose = isConfirmingAppClose.value;
pendingCloseTabId.value = null;
showCloseConfirm.value = false;
pendingBatchCloseTabIds.value = null;
pendingBatchCloseFinalActiveTabId.value = undefined;
pendingBatchCloseComplete = null;
isConfirmingAppClose.value = false;
closeConfirmContext.value = "tab";
@@ -2015,6 +2026,7 @@ export const useQueryStore = defineStore("query", () => {
if (finalActiveTabId !== undefined) {
activeTabId.value = finalActiveTabId && tabs.value.some((tab) => tab.id === finalActiveTabId) ? finalActiveTabId : null;
}
if (batchIds) onBatchComplete?.();
}
function cancelClosePendingTab() {
@@ -2022,6 +2034,7 @@ export const useQueryStore = defineStore("query", () => {
showCloseConfirm.value = false;
pendingBatchCloseTabIds.value = null;
pendingBatchCloseFinalActiveTabId.value = undefined;
pendingBatchCloseComplete = null;
isConfirmingAppClose.value = false;
closeConfirmContext.value = "tab";
}
@@ -2054,12 +2067,14 @@ export const useQueryStore = defineStore("query", () => {
const pendingId = pendingCloseTabId.value;
const batchIds = pendingBatchCloseTabIds.value?.filter((id) => tabs.value.some((tab) => tab.id === id)) ?? null;
const finalActiveTabId = pendingBatchCloseFinalActiveTabId.value;
const onBatchComplete = pendingBatchCloseComplete;
const confirmingAppClose = isConfirmingAppClose.value;
pendingCloseTabId.value = null;
showCloseConfirm.value = false;
pendingBatchCloseTabIds.value = null;
pendingBatchCloseFinalActiveTabId.value = undefined;
pendingBatchCloseComplete = null;
isConfirmingAppClose.value = false;
closeConfirmContext.value = "tab";
@@ -2070,6 +2085,7 @@ export const useQueryStore = defineStore("query", () => {
if (finalActiveTabId !== undefined) {
activeTabId.value = finalActiveTabId && tabs.value.some((tab) => tab.id === finalActiveTabId) ? finalActiveTabId : null;
}
if (batchIds) onBatchComplete?.();
return "tabs" as const;
}
@@ -2081,6 +2097,22 @@ export const useQueryStore = defineStore("query", () => {
);
}
function closeRightTabs(id: string, onComplete?: () => void) {
const target = tabs.value.find((tab) => tab.id === id);
if (!target) return;
const groupedTabs = tabs.value.filter((tab) => Boolean(tab.pinned) === Boolean(target.pinned));
const targetIndex = groupedTabs.findIndex((tab) => tab.id === id);
const ids = groupedTabs.slice(targetIndex + 1).map((tab) => tab.id);
if (ids.length === 0) {
onComplete?.();
return;
}
const finalActiveTabId = activeTabId.value && !ids.includes(activeTabId.value) ? activeTabId.value : id;
beginBatchClose(ids, finalActiveTabId, onComplete);
}
function finalActiveTabAfterClosing(ids: string[]) {
const closingIds = new Set(ids);
const activeTab = activeTabId.value ? tabs.value.find((tab) => tab.id === activeTabId.value) : undefined;
@@ -5302,6 +5334,7 @@ export const useQueryStore = defineStore("query", () => {
discardTabChanges,
requestAppCloseConfirmation,
closeOtherTabs,
closeRightTabs,
closeOtherRegularTabs,
closeRegularTabs,
closeOtherFixedTabs,