feat(ui): support customizable maximum tab width
This commit is contained in:
1 parent
8a2241c36e
commit
9419e18b79
23 files changed
+242
-6
No files matched your search
@@ -42,6 +42,7 @@ import {
|
||||
Clock3,
|
||||
Copy,
|
||||
Database,
|
||||
FoldHorizontal,
|
||||
ListFilter,
|
||||
ListOrdered,
|
||||
Maximize2,
|
||||
@@ -189,8 +190,15 @@ const showTabTreeGuides = computed(() => isVerticalLayout.value && !isTabBarColl
|
||||
// the shared vertical rail width; fill that rail so nested pane bars stay in
|
||||
// sync while the resize handle updates the outer panel (issue #9977).
|
||||
const tabBarStyle = computed<CSSProperties | undefined>(() => {
|
||||
if (!isVerticalLayout.value) return undefined;
|
||||
return { width: "100%", flex: "0 0 100%" };
|
||||
const styles: CSSProperties = {};
|
||||
if (isVerticalLayout.value) {
|
||||
styles.width = "100%";
|
||||
styles.flex = "0 0 100%";
|
||||
}
|
||||
if (!isVerticalLayout.value && settingsStore.editorSettings.tabMaxWidth > 0) {
|
||||
styles["--tab-max-width"] = `${settingsStore.editorSettings.tabMaxWidth}px`;
|
||||
}
|
||||
return Object.keys(styles).length > 0 ? styles : undefined;
|
||||
});
|
||||
const tabBarCollapseIcon = computed(() => {
|
||||
const isLeft = settingsStore.editorSettings.tabPlacement === "left";
|
||||
@@ -375,8 +383,15 @@ const tabPlacementItems = computed(() => [
|
||||
{ value: "left", label: t("settings.tabPlacementLeft") },
|
||||
{ value: "right", label: t("settings.tabPlacementRight") },
|
||||
]);
|
||||
const tabMaxWidthItems = computed(() => [
|
||||
{ value: 0, label: t("settings.tabMaxWidthUnlimited") },
|
||||
{ value: 160, label: t("settings.tabMaxWidthCompact") },
|
||||
{ value: 200, label: t("settings.tabMaxWidthMedium") },
|
||||
{ value: 240, label: t("settings.tabMaxWidthStandard") },
|
||||
{ value: 320, label: t("settings.tabMaxWidthWide") },
|
||||
]);
|
||||
|
||||
type TabPreferencePatch = Partial<Pick<EditorSettings, "tabPlacement" | "tabGroupMode" | "tabSortMode" | "tabGroupCustomizations">>;
|
||||
type TabPreferencePatch = Partial<Pick<EditorSettings, "tabPlacement" | "tabGroupMode" | "tabSortMode" | "tabGroupCustomizations" | "tabMaxWidth">>;
|
||||
|
||||
async function persistTabPreferences(partial: TabPreferencePatch) {
|
||||
try {
|
||||
@@ -398,6 +413,10 @@ function updateTabPlacement(value: string) {
|
||||
if (value === "top" || value === "bottom" || value === "left" || value === "right") void persistTabPreferences({ tabPlacement: value });
|
||||
}
|
||||
|
||||
function updateTabMaxWidth(value: number) {
|
||||
if (Number.isFinite(value) && value >= 0) void persistTabPreferences({ tabMaxWidth: value });
|
||||
}
|
||||
|
||||
function databaseTabGroupKey(tab: QueryTab) {
|
||||
const database = tab.database || "";
|
||||
if (connectionStore.getConfig(tab.connectionId)?.db_type === "redis") {
|
||||
@@ -879,8 +898,9 @@ const tabOrganizationItems = computed(() => [
|
||||
groupLabel: index === 0 ? t("settings.tabGroup") : undefined,
|
||||
})),
|
||||
...tabSortItems.value.map((item, index) => ({ ...item, value: `sort:${item.value}`, icon: { manual: ListOrdered, "created-asc": Clock3, "title-asc": ArrowDownAZ }[item.value], separatorBefore: index === 0, groupLabel: index === 0 ? t("settings.tabSort") : undefined })),
|
||||
...tabMaxWidthItems.value.map((item, index) => ({ ...item, value: `maxwidth:${item.value}`, icon: item.value === 0 ? Maximize2 : FoldHorizontal, separatorBefore: index === 0, groupLabel: index === 0 ? t("settings.tabMaxWidth") : undefined })),
|
||||
]);
|
||||
const selectedTabOrganizationItems = computed(() => [`placement:${settingsStore.editorSettings.tabPlacement}`, `group:${settingsStore.editorSettings.tabGroupMode}`, `sort:${settingsStore.editorSettings.tabSortMode}`]);
|
||||
const selectedTabOrganizationItems = computed(() => [`placement:${settingsStore.editorSettings.tabPlacement}`, `group:${settingsStore.editorSettings.tabGroupMode}`, `sort:${settingsStore.editorSettings.tabSortMode}`, `maxwidth:${settingsStore.editorSettings.tabMaxWidth}`]);
|
||||
|
||||
function selectTabOrganizationItem(value: string) {
|
||||
const [section, option] = value.split(":");
|
||||
@@ -888,6 +908,7 @@ function selectTabOrganizationItem(value: string) {
|
||||
if (section === "placement") updateTabPlacement(option);
|
||||
else if (section === "group") updateTabGroupMode(option);
|
||||
else if (section === "sort") updateTabSortMode(option);
|
||||
else if (section === "maxwidth") updateTabMaxWidth(Number(option));
|
||||
}
|
||||
|
||||
function getTabGroupMenuItems(tab: QueryTab): ContextMenuItem[] {
|
||||
@@ -1566,6 +1587,7 @@ watch(
|
||||
props.specialPageTabs?.driverStoreOpen,
|
||||
settingsStore.editorSettings.tabLayout,
|
||||
settingsStore.editorSettings.tabGroupMode,
|
||||
settingsStore.editorSettings.tabMaxWidth,
|
||||
compactTabTitle.value,
|
||||
Array.from(collapsedTabGroups.value).sort().join("|"),
|
||||
],
|
||||
@@ -1618,6 +1640,7 @@ watch([() => props.specialPageTabs?.settingsActive, () => props.specialPageTabs?
|
||||
:data-group-id="groupId"
|
||||
:data-group-mode="settingsStore.editorSettings.tabGroupMode"
|
||||
:data-placement="settingsStore.editorSettings.tabPlacement"
|
||||
:data-has-max-tab-width="!isVerticalLayout && settingsStore.editorSettings.tabMaxWidth > 0"
|
||||
>
|
||||
<!-- Compact vertical toolbar: search, tab organization, collapse. -->
|
||||
<div v-if="isVerticalLayout" class="flex h-9 shrink-0 items-center gap-0.5 border-b p-1" :class="isTabBarCollapsed ? 'justify-center' : ''">
|
||||
|
||||
+24
@@ -45,6 +45,7 @@ import EditorGroupTabBar from "../EditorGroupTabBar.vue";
|
||||
import { createNoopEditorToolbarActions, EDITOR_TOOLBAR_ACTIONS, type EditorToolbarActions } from "../editorToolbarActions";
|
||||
import { useConnectionStore } from "@/stores/connectionStore";
|
||||
import { useQueryStore } from "@/stores/queryStore";
|
||||
import { useSettingsStore } from "@/stores/settingsStore";
|
||||
import type { ConnectionConfig } from "@/types/database";
|
||||
|
||||
function createHost(): HTMLDivElement {
|
||||
@@ -729,4 +730,27 @@ describe("EditorGroupTabBar behavior", () => {
|
||||
app.unmount();
|
||||
host.remove();
|
||||
});
|
||||
|
||||
it("applies --tab-max-width and data-has-max-tab-width when tabMaxWidth is configured", async () => {
|
||||
const store = useQueryStore();
|
||||
const settings = useSettingsStore();
|
||||
settings.editorSettings.tabMaxWidth = 240;
|
||||
const firstId = store.createTab("pg-1", "app", "Query 1", "query");
|
||||
const mainGroup = store.groups[0];
|
||||
const { app, host } = mountBar(mainGroup.id, [firstId], firstId, pinia);
|
||||
await settle();
|
||||
|
||||
const bar = host.querySelector<HTMLElement>(".app-tab-bar")!;
|
||||
expect(bar.dataset.hasMaxTabWidth).toBe("true");
|
||||
expect(bar.style.getPropertyValue("--tab-max-width")).toBe("240px");
|
||||
|
||||
// Setting tabMaxWidth to 0 removes the limit
|
||||
settings.editorSettings.tabMaxWidth = 0;
|
||||
await settle();
|
||||
expect(bar.dataset.hasMaxTabWidth).toBe("false");
|
||||
expect(bar.style.getPropertyValue("--tab-max-width")).toBe("");
|
||||
|
||||
app.unmount();
|
||||
host.remove();
|
||||
});
|
||||
});
|
||||
@@ -334,6 +334,7 @@
|
||||
|
||||
.app-tab-bar:not(.vertical-tab-layout) .app-tab-pill {
|
||||
border: 0.5px solid color-mix(in oklch, var(--foreground) 14%, var(--border));
|
||||
max-width: var(--tab-max-width, none);
|
||||
}
|
||||
|
||||
.app-tab-bar:not(.vertical-tab-layout) .app-tab-pill[data-active-tab="true"] {
|
||||
@@ -843,7 +844,7 @@
|
||||
* expand smoothly instead of appearing and disappearing in one frame. */
|
||||
.app-tab-bar:not(.vertical-tab-layout):not(:has(.wrap-mode)) .tab-group-entry {
|
||||
min-width: 0;
|
||||
max-width: var(--tab-group-entry-expanded-width, 100%);
|
||||
max-width: var(--tab-group-entry-expanded-width, var(--tab-max-width, 100%));
|
||||
max-height: 2rem;
|
||||
overflow: hidden;
|
||||
transition:
|
||||
@@ -859,6 +860,11 @@
|
||||
flex: none;
|
||||
}
|
||||
|
||||
.app-tab-bar:not(.vertical-tab-layout):not(:has(.wrap-mode))[data-has-max-tab-width="true"] .tab-group-entry[data-tab-group-id] > .tab-group-tab {
|
||||
min-width: var(--tab-group-entry-expanded-width, 0) !important;
|
||||
max-width: var(--tab-max-width, 100%);
|
||||
}
|
||||
|
||||
/* The classic single-row strip is 2.25rem tall. Keep ordinary tab wrappers
|
||||
* at the full row height so direct tabs such as Settings do not look taller. */
|
||||
.app-tab-bar.classic-tab-layout:not(.vertical-tab-layout):not(:has(.wrap-mode)) .tab-group-entry {
|
||||
@@ -906,6 +912,10 @@
|
||||
|
||||
/* Do not animate dimensions in wrapped mode. The browser must reflow the
|
||||
* complete set of rows immediately when a group is expanded or collapsed. */
|
||||
.app-tab-scroll.wrap-mode .tab-group-entry {
|
||||
max-width: var(--tab-max-width, none);
|
||||
}
|
||||
|
||||
.app-tab-scroll.wrap-mode .tab-group-entry,
|
||||
.app-tab-scroll.wrap-mode .tab-group-entry--collapsed,
|
||||
.app-tab-scroll.wrap-mode .tab-group-tab,
|
||||
|
||||
Reference in new issue
Block a user