feat(ui): support customizable maximum tab width

This commit is contained in:
lxk955 authored and GitHub committed 2026-10-04 16:33:28 +08:00
1 parent 8a2241c36e
commit 9419e18b79
23 files changed
+242 -6

No files matched your search

@@ -64,6 +64,7 @@ const editorSettingCategoryOverrides: Partial<Record<string, BackupSettingsCateg
tabGroupMode: "appearance",
tabGroupCustomizations: "appearance",
tabSortMode: "appearance",
tabMaxWidth: "appearance",
compactTabTitle: "appearance",
executeModeDefaultVersion: "editor",
globalConnectTimeoutSecs: "editor",
@@ -118,6 +118,7 @@ import {
type SqlCompletionTriggerMode,
type SqlTableCompletionSchemaQualification,
type TableHoverLookupMode,
normalizeTabMaxWidth,
SIDEBAR_INDENT_MIN,
SIDEBAR_INDENT_MAX,
SIDEBAR_FONT_SIZE_MIN,
@@ -720,6 +721,7 @@ const editTabPlacement = ref<TabPlacement>(settingsStore.editorSettings.tabPlace
const editColorizeConnectionTabs = ref(settingsStore.editorSettings.colorizeConnectionTabs);
const editTabGroupMode = ref<TabGroupMode>(settingsStore.editorSettings.tabGroupMode);
const editTabSortMode = ref<TabSortMode>(settingsStore.editorSettings.tabSortMode);
const editTabMaxWidth = ref<number>(settingsStore.editorSettings.tabMaxWidth);
const editShowTrayIcon = ref(settingsStore.desktopSettings.show_tray_icon);
const editQuitOnClose = ref(settingsStore.desktopSettings.quit_on_close);
const desktopCloseBehaviorResetPending = ref(false);
@@ -1094,6 +1096,7 @@ function currentEditorSettingsDraft(): EditorSettingsDraft {
colorizeConnectionTabs: editColorizeConnectionTabs.value,
tabGroupMode: editTabGroupMode.value,
tabSortMode: editTabSortMode.value,
tabMaxWidth: editTabMaxWidth.value,
showColumnCommentsInHeader: editShowColumnCommentsInHeader.value,
showColumnTypesInHeader: editShowColumnTypesInHeader.value,
showColumnHeaderTooltips: editShowColumnHeaderTooltips.value,
@@ -1769,6 +1772,7 @@ function syncEditorSettingsDraftFromStore() {
editColorizeConnectionTabs.value = settingsStore.editorSettings.colorizeConnectionTabs;
editTabGroupMode.value = settingsStore.editorSettings.tabGroupMode;
editTabSortMode.value = settingsStore.editorSettings.tabSortMode;
editTabMaxWidth.value = settingsStore.editorSettings.tabMaxWidth;
editShowColumnCommentsInHeader.value = settingsStore.editorSettings.showColumnCommentsInHeader;
editShowColumnTypesInHeader.value = settingsStore.editorSettings.showColumnTypesInHeader;
editShowColumnHeaderTooltips.value = settingsStore.editorSettings.showColumnHeaderTooltips;
@@ -1919,6 +1923,7 @@ const editorSettingsDraftRefs: EditorSettingsDraftRefMap = {
colorizeConnectionTabs: editColorizeConnectionTabs,
tabGroupMode: editTabGroupMode,
tabSortMode: editTabSortMode,
tabMaxWidth: editTabMaxWidth,
showColumnCommentsInHeader: editShowColumnCommentsInHeader,
showColumnTypesInHeader: editShowColumnTypesInHeader,
showColumnHeaderTooltips: editShowColumnHeaderTooltips,
@@ -2465,6 +2470,7 @@ function resetDefaultsForTab(tab: SettingsCategory) {
editColorizeConnectionTabs.value = DEFAULT_EDITOR_SETTINGS.colorizeConnectionTabs;
editTabGroupMode.value = DEFAULT_EDITOR_SETTINGS.tabGroupMode;
editTabSortMode.value = DEFAULT_EDITOR_SETTINGS.tabSortMode;
editTabMaxWidth.value = DEFAULT_EDITOR_SETTINGS.tabMaxWidth;
editShowTrayIcon.value = DEFAULT_DESKTOP_SETTINGS.show_tray_icon;
editQuitOnClose.value = DEFAULT_DESKTOP_SETTINGS.quit_on_close;
desktopCloseBehaviorResetPending.value = true;
@@ -3160,6 +3166,10 @@ function setTabSortMode(value: TabSortMode) {
editTabSortMode.value = value;
}
function setTabMaxWidth(value: number) {
editTabMaxWidth.value = normalizeTabMaxWidth(value);
}
function setSidebarActivation(value: "single" | "double") {
editSidebarActivation.value = value;
}
@@ -7579,7 +7589,7 @@ onUnmounted(() => {
</div>
<div class="settings-appearance-group">
<div class="grid grid-cols-1 gap-4 md:grid-cols-3">
<div class="grid grid-cols-1 gap-4 sm:grid-cols-2 xl:grid-cols-4">
<div class="space-y-2">
<Label>{{ t("settings.tabPlacement") }}</Label>
<Select :model-value="editTabPlacement" @update:model-value="setTabPlacement($event as TabPlacement)">
@@ -7616,10 +7626,24 @@ onUnmounted(() => {
</SelectContent>
</Select>
</div>
<div class="space-y-2">
<Label>{{ t("settings.tabMaxWidth") }}</Label>
<Select :model-value="String(editTabMaxWidth)" @update:model-value="setTabMaxWidth(Number($event))">
<SelectTrigger class="w-full"><SelectValue /></SelectTrigger>
<SelectContent>
<SelectItem value="0">{{ t("settings.tabMaxWidthUnlimited") }}</SelectItem>
<SelectItem value="160">{{ t("settings.tabMaxWidthCompact") }}</SelectItem>
<SelectItem value="200">{{ t("settings.tabMaxWidthMedium") }}</SelectItem>
<SelectItem value="240">{{ t("settings.tabMaxWidthStandard") }}</SelectItem>
<SelectItem value="320">{{ t("settings.tabMaxWidthWide") }}</SelectItem>
</SelectContent>
</Select>
</div>
</div>
<div class="space-y-1 text-xs text-muted-foreground">
<p>{{ t("settings.tabPlacementDescription") }}</p>
<p>{{ t("settings.tabOrganizationDescription") }}</p>
<p>{{ t("settings.tabMaxWidthDescription") }}</p>
</div>
</div>
@@ -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' : ''">
@@ -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,