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。
TypeScript aicliclickhousedatabasedatabase-clientdatabase-managementdockerguimcpmongodbmysqlpostgresqlredisrustsql-serversqlitetaurivue
fix(tabs): keep overflow arrow stable and follow title clipping
dakenb79b79d6d7af
diff --git a/apps/desktop/src/components/layout/EditorGroupTabBar.vue b/apps/desktop/src/components/layout/EditorGroupTabBar.vueindex 56a114a5b4..3813706a4c 100644--- a/apps/desktop/src/components/layout/EditorGroupTabBar.vue+++ b/apps/desktop/src/components/layout/EditorGroupTabBar.vue@@ -84,6 +84,7 @@ import { useQueryStore } from "@/stores/queryStore";import { useSettingsStore } from "@/stores/settingsStore";import type { EditorSettings } from "@/stores/settingsStore";import { useTabScroll } from "@/composables/useTabScroll";+import { useTabTitleTruncation } from "@/composables/useTabTitleTruncation";import { useToast } from "@/composables/useToast";import { hexToRgba } from "@/lib/common/color";import { copyToClipboard } from "@/lib/common/clipboard";@@ -137,6 +138,7 @@ const canNewQuery = computed(() => toolbar?.canNewQuery.value ?? false);const { toast } = useToast();const tabsContainerRef = ref<HTMLElement | null>(null);const { hasTabOverflow, scrollThumbLeftPercent, scrollThumbWidthPercent, isScrollbarDragging, updateScrollButtons, onTabsWheel, startScrollbarDrag } = useTabScroll(tabsContainerRef);+const { hasTruncatedTabTitle } = useTabTitleTruncation(tabsContainerRef);const fixedTabsRowRef = ref<HTMLElement | null>(null);const regularTabsRowRef = ref<HTMLElement | null>(null);const fixedTabsScroll = useTabScroll(fixedTabsRowRef);@@ -344,13 +346,25 @@ function revealActiveTabAfterLayout() {const showOverflowControl = computed(() => {void tabLayoutRevision.value;- const hasOverflow = hasHorizontalFixedRows.value ? fixedTabsScroll.hasTabOverflow.value || regularTabsScroll.hasTabOverflow.value || hasHorizontalRowOverflow() : hasTabOverflow.value;- return props.tabs.length > 0 && hasOverflow && !isWrapLayout.value && !isVerticalLayout.value;+ // A single-row strip hides tabs in two ways: they scroll out of the viewport+ // (real overflow) or they stay in it and ellipsize their labels, which the+ // scroll box cannot see because a capped pill narrows itself instead of+ // overflowing (useTabTitleTruncation). The two-row layout decides from its+ // rows' scroll extents alone: its first row narrows itself by the arrow's+ // reserved width (.tab-section-frame--with-overflow-control), so feeding+ // clipping back into the arrow there would rebuild the loop that the constant+ // reservation exists to break.+ const hasHiddenTab = hasHorizontalFixedRows.value ? fixedTabsScroll.hasTabOverflow.value || regularTabsScroll.hasTabOverflow.value || hasHorizontalRowOverflow() : hasTabOverflow.value || hasTruncatedTabTitle.value;+ return props.tabs.length > 0 && hasHiddenTab && !isWrapLayout.value && !isVerticalLayout.value;});const tabTailDragRegionClass = computed(() => {if (isWrapLayout.value || isVerticalLayout.value) return "w-0 flex-none self-stretch";- if (showOverflowControl.value) return "tab-tail-overflow-spacer flex-none self-stretch";- return "min-w-8 flex-1 self-stretch";+ // Keep a constant footprint. Letting this spacer (and the strip's reserved+ // padding) depend on showOverflowControl made the measured scroll viewport+ // respond to its own measurement, flipping the overflow arrow every frame for+ // a single near-full-width tab. Dropping the 32px minimum turns it into a+ // pure filler: it grows into spare space but never manufactures overflow.+ return "min-w-0 flex-1 self-stretch";});watch(@@ -1956,7 +1970,7 @@ watch([() => props.specialPageTabs?.settingsActive, () => props.specialPageTabs?<span v-else-if="!isTabBarCollapsed" class="inline-flex min-w-0 flex-1 items-center gap-0.5 overflow-hidden text-foreground"><span v-if="isDirtyTab(entry.tab)" aria-hidden="true" class="dirty-tab-marker">*</span><span class="flex min-w-0 flex-1 items-center overflow-hidden">- <span class="min-w-0 truncate" :style="tabTitleStyle(entry.tab)">{{ tabTitleBase(entry.tab) }}</span>+ <span class="min-w-0 truncate" :style="tabTitleStyle(entry.tab)" data-tab-title-base>{{ tabTitleBase(entry.tab) }}</span><span v-if="tabTitleSuffixText(entry.tab)" class="tab-title-suffix max-w-full shrink-0 overflow-hidden pl-1 text-ellipsis whitespace-nowrap" :style="tabTitleStyle(entry.tab)" data-tab-title-suffix>{{ tabTitleSuffixText(entry.tab) }}</span></span></span>diff --git a/apps/desktop/src/components/layout/appTabBar.css b/apps/desktop/src/components/layout/appTabBar.cssindex 683301e32b..c1de0b923f 100644--- a/apps/desktop/src/components/layout/appTabBar.css+++ b/apps/desktop/src/components/layout/appTabBar.css@@ -175,12 +175,6 @@flex: 0 0 0;}-.horizontal-fixed-tabs-scroll .tab-section--horizontal > .tab-tail-overflow-spacer[data-tauri-drag-region] {- width: 1px;- min-width: 1px;- flex-basis: 1px;-}-/* Keep the overflow affordance out of the measurement box. Otherwise its own* width reduces the scroll viewport and can create a false overflow state. */.tab-overflow-control {@@ -192,7 +186,16 @@justify-content: flex-end;}-.has-tab-overflow-control .app-tab-strip {+/* The single-row layouts reserve the overflow affordance's width at all times.+ * Deriving it from showOverflowControl tied the scroll viewport to its own+ * measurement: a single near-full-width tab showed the arrow, the arrow+ * narrowed the strip, the narrower strip re-measured as "fits", the arrow hid,+ * the strip re-widened — an endless per-frame flicker. A constant reservation+ * keeps hasTabOverflow stable, so the arrow becomes a pure overlay that never+ * alters the layout it is measured from. Keep the value in step with the+ * arrow's own offset (`.tab-overflow-control`'s `right-[…]` classes), which is+ * what clears the last tab. */+.app-tab-bar:not(.horizontal-fixed-tabs):not(.vertical-tab-layout):not(.tab-wrap-mode) .app-tab-strip {padding-inline-end: 2.5rem;}diff --git a/apps/desktop/src/composables/__tests__/useTabTitleTruncation.spec.ts b/apps/desktop/src/composables/__tests__/useTabTitleTruncation.spec.tsnew file mode 100644index 0000000000..0f7f0d0ded--- /dev/null+++ b/apps/desktop/src/composables/__tests__/useTabTitleTruncation.spec.ts@@ -0,0 +1,116 @@+// @vitest-environment happy-dom+import { createApp, defineComponent, h, nextTick, ref } from "vue";+import type { Ref } from "vue";+import { afterEach, describe, expect, it } from "vitest";+import { useTabTitleTruncation } from "../useTabTitleTruncation";++// happy-dom has no layout engine and no ResizeObserver, so the observer plumbing+// cannot be exercised here: these specs pin the measurement contract — which+// elements count as clipped and how the flag is aggregated — through the+// exposed measureTabTitleTruncation.+interface Harness {+ stripRef: Ref<HTMLElement | null>;+ hasTruncatedTabTitle: Ref<boolean>;+ measure: () => void;+}++let mounted: ReturnType<typeof createApp> | null = null;++function createHarness(): Harness {+ const stripRef = ref<HTMLElement | null>(null);+ let truncatedRef: Ref<boolean> | undefined;+ let measureFn: () => void = () => {};+ const app = createApp(+ defineComponent({+ setup() {+ const { hasTruncatedTabTitle, measureTabTitleTruncation } = useTabTitleTruncation(stripRef);+ truncatedRef = hasTruncatedTabTitle;+ measureFn = measureTabTitleTruncation;+ return () => h("div");+ },+ }),+ );+ app.mount(document.createElement("div"));+ mounted = app;+ return { stripRef, hasTruncatedTabTitle: truncatedRef!, measure: () => measureFn() };+}++/** A title element whose box is `boxWidth` wide while its text needs `contentWidth`. */+function title(attribute: "data-tab-title-base" | "data-tab-title-suffix", boxWidth: number, contentWidth: number): HTMLElement {+ const element = document.createElement("span");+ element.setAttribute(attribute, "");+ Object.defineProperty(element, "clientWidth", { value: boxWidth, configurable: true });+ Object.defineProperty(element, "scrollWidth", { value: contentWidth, configurable: true });+ return element;+}++function stripOf(...titles: HTMLElement[]): HTMLElement {+ const strip = document.createElement("div");+ strip.append(...titles);+ return strip;+}++async function attach(harness: Harness, strip: HTMLElement | null, ticks = 3): Promise<void> {+ harness.stripRef.value = strip;+ for (let i = 0; i < ticks; i += 1) {+ await nextTick();+ }+}++describe("useTabTitleTruncation", () => {+ afterEach(() => {+ mounted?.unmount();+ mounted = null;+ document.body.innerHTML = "";+ });++ it("reports a tab whose title is ellipsized", async () => {+ const harness = createHarness();+ await attach(harness, stripOf(title("data-tab-title-base", 120, 640)));++ harness.measure();++ expect(harness.hasTruncatedTabTitle.value).toBe(true);+ });++ it("stays hidden while every title fits, including sub-pixel rounding", async () => {+ const harness = createHarness();+ await attach(harness, stripOf(title("data-tab-title-base", 640, 640), title("data-tab-title-suffix", 90, 91)));++ harness.measure();++ expect(harness.hasTruncatedTabTitle.value).toBe(false);+ });++ it("treats a clipped title suffix as a hidden tab too", async () => {+ const harness = createHarness();+ await attach(harness, stripOf(title("data-tab-title-base", 120, 120), title("data-tab-title-suffix", 60, 180)));++ harness.measure();++ expect(harness.hasTruncatedTabTitle.value).toBe(true);+ });++ it("re-reads a replacement strip instead of keeping the old reading", async () => {+ const harness = createHarness();+ await attach(harness, stripOf(title("data-tab-title-base", 120, 640)));+ harness.measure();+ expect(harness.hasTruncatedTabTitle.value).toBe(true);++ await attach(harness, stripOf(title("data-tab-title-base", 640, 640)));+ harness.measure();++ expect(harness.hasTruncatedTabTitle.value).toBe(false);+ });++ it("reports no clipping while no strip is attached", async () => {+ const harness = createHarness();+ await attach(harness, stripOf(title("data-tab-title-base", 120, 640)));+ harness.measure();+ expect(harness.hasTruncatedTabTitle.value).toBe(true);++ await attach(harness, null);++ expect(harness.hasTruncatedTabTitle.value).toBe(false);+ });+});diff --git a/apps/desktop/src/composables/useTabTitleTruncation.ts b/apps/desktop/src/composables/useTabTitleTruncation.tsnew file mode 100644index 0000000000..3cb8e51e3d--- /dev/null+++ b/apps/desktop/src/composables/useTabTitleTruncation.ts@@ -0,0 +1,116 @@+import { onUnmounted, ref, watch, type Ref } from "vue";+import { deferUntilPanelResizeEnd } from "@/lib/app/panelResizeState";++/**+ * A tab's label is ellipsized in two independent halves: the base title and its+ * suffix. Either one clipping means the user is not seeing the whole tab.+ */+const TITLE_SELECTOR = "[data-tab-title-base], [data-tab-title-suffix]";+/** Content wider than its box by ±1px is sub-pixel rounding, not ellipsis. */+const CLIP_TOLERANCE_PX = 1;++/**+ * Tracks whether the tab strip ellipsizes any of the titles it shows.+ *+ * `.tab-group-entry` is capped at `var(--tab-max-width, 100%)`, so tabs narrow+ * themselves down to the strip and clip their labels instead of overflowing it.+ * The scroll box then reports scrollWidth === clientWidth and the overflow check+ * in useTabScroll can never see those tabs — yet they are exactly what the user+ * reads as "not all tabs fit". The strip's dropdown arrow therefore has to+ * follow the clipping as well as the overflow, or a strip whose titles are all+ * ellipsized offers no way to reach them.+ *+ * Measurement contract: nothing the arrow controls may change the widths read+ * here. The arrow is an absolutely positioned sibling of the strip and the+ * strip's right-hand reservation in appTabBar.css is constant, so toggling it is+ * invisible to these measurements. A reservation derived from the arrow's own+ * visibility would turn this into the feedback loop that flipped it every frame.+ *+ * @param stripRef the strip element holding the titles (its scroll container)+ */+export function useTabTitleTruncation(stripRef: Ref<HTMLElement | null>) {+ const hasTruncatedTabTitle = ref(false);+ let resizeObserver: ResizeObserver | undefined;+ let mutationObserver: MutationObserver | undefined;+ let updateFrame = 0;++ function measure() {+ const strip = stripRef.value;+ if (!strip) {+ hasTruncatedTabTitle.value = false;+ return;+ }+ // clientWidth/scrollWidth reads force a synchronous relayout of the whole+ // document; skip them while a divider drag is in flight and read once when+ // the drag ends.+ if (deferUntilPanelResizeEnd(measure)) return;+ hasTruncatedTabTitle.value = Array.from(strip.querySelectorAll<HTMLElement>(TITLE_SELECTOR)).some((title) => title.scrollWidth - title.clientWidth > CLIP_TOLERANCE_PX);+ }++ function scheduleMeasure() {+ if (updateFrame) return;+ const update = () => {+ updateFrame = 0;+ measure();+ };+ if (typeof requestAnimationFrame === "function") {+ updateFrame = requestAnimationFrame(update);+ } else {+ window.setTimeout(update, 0);+ }+ }++ // A pill that is already capped keeps its width when its label grows, so the+ // strip's own box never reports a rename, a dirty marker or an extra tab;+ // those move the pill's box. Watch every pill as well, and re-arm on DOM+ // changes, which is what actually adds and removes pills.+ function observePills() {+ const strip = stripRef.value;+ if (!strip || !resizeObserver) return;+ for (const pill of strip.querySelectorAll<HTMLElement>("[data-tab-id]")) resizeObserver.observe(pill);+ }++ watch(+ stripRef,+ (strip) => {+ resizeObserver?.disconnect();+ mutationObserver?.disconnect();+ resizeObserver = undefined;+ mutationObserver = undefined;+ if (!strip) {+ hasTruncatedTabTitle.value = false;+ return;+ }+ if (typeof ResizeObserver !== "undefined") {+ resizeObserver = new ResizeObserver(scheduleMeasure);+ resizeObserver.observe(strip);+ observePills();+ }+ if (typeof MutationObserver !== "undefined") {+ mutationObserver = new MutationObserver(() => {+ observePills();+ scheduleMeasure();+ });+ mutationObserver.observe(strip, { childList: true, characterData: true, subtree: true });+ }+ // The previous reading is kept until this one lands: on a strip remount+ // (layout switch, pane rebuild) the tabs and their clipping are usually+ // unchanged, and clearing the flag first would blink the arrow off.+ scheduleMeasure();+ },+ // `immediate` covers a caller that hands over an already-attached strip; a+ // null first reading is free and the watcher still runs on the real change.+ { flush: "post", immediate: true },+ );++ onUnmounted(() => {+ resizeObserver?.disconnect();+ mutationObserver?.disconnect();+ resizeObserver = undefined;+ mutationObserver = undefined;+ if (updateFrame && typeof cancelAnimationFrame === "function") cancelAnimationFrame(updateFrame);+ updateFrame = 0;+ });++ return { hasTruncatedTabTitle, measureTabTitleTruncation: measure };+}