fix(tabs): restore close-right tab action
This commit is contained in:
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"\);/);
|
||||
});
|
||||
});
|
||||
Reference in new issue
Block a user