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(sidebar): improve horizontal scrolling
二丫讲梵590a311b5a74
diff --git a/apps/desktop/src/components/sidebar/ConnectionTree.vue b/apps/desktop/src/components/sidebar/ConnectionTree.vueindex 09eecb7473..5e8ef06ab7 100644--- a/apps/desktop/src/components/sidebar/ConnectionTree.vue+++ b/apps/desktop/src/components/sidebar/ConnectionTree.vue@@ -66,7 +66,7 @@ import { insertSidebarTableSearchControls, isSidebarTableSearchControlNode } froimport { createSidebarTableSearchDebouncer, scheduleExclusiveSidebarTableSearchDebounce } from "@/lib/sidebar/sidebarTableSearchIndex";import TreeItem from "./TreeItem.vue";import ProductionContextBadge from "@/components/common/ProductionContextBadge.vue";-import { showSidebarStickyProductionBadge } from "@/lib/sidebar/sidebarProductionBadge";+import { isSidebarProductionContainer, showSidebarRowProductionBadge, showSidebarStickyProductionBadge } from "@/lib/sidebar/sidebarProductionBadge";import { resolvePlainStickyContainerIndex } from "@/lib/sidebar/sidebarStickyProductionContext";import ActiveConnectionFilterButton from "./ActiveConnectionFilterButton.vue";import SidebarListOptionsIcon from "./SidebarListOptionsIcon.vue";@@ -96,7 +96,9 @@ import { resetSidebarTreeDialogState } from "./sidebarTreeDialogState";import { SidebarDdlViewDialog, SidebarElasticsearchIndexMetadataDialog, SidebarObjectSourceDialog, SidebarProcedureExecutionDialog, SidebarVisibleDatabasesDialog, SidebarVisibleNacosNamespacesDialog, SidebarVisibleSchemasDialog } from "./sidebarAsyncDialogs";import { sortConnectionListForDisplay } from "@/lib/sidebar/connectionListSort";import { sidebarDisplayTableName } from "@/lib/sidebar/sidebarTableNameDisplay";-import { alignedSidebarCommentLabelWidths, isSidebarCommentAlignableNode, sidebarTreeNaturalContentWidth, sidebarTreeNodeComment, usesFullWidthTreeLabel } from "@/lib/sidebar/sidebarTreeItemLayout";+import { sidebarTreeDisplayLabel, sidebarTreeSecondaryValue } from "@/lib/sidebar/sidebarTreeLabel";+import { canTreeNodePin, sidebarPinnedActionSlotWidthPx, alignedSidebarCommentLabelWidths, isSidebarCommentAlignableNode, sidebarTreeNaturalContentWidth, sidebarTreeNodeComment, usesFullWidthTreeLabel } from "@/lib/sidebar/sidebarTreeItemLayout";+import { sidebarHorizontalWheelDelta } from "@/lib/sidebar/sidebarScrollbar";import { formatSidebarObjectStorage, sidebarTableStorageScopes, supportsSidebarTableStorage } from "@/lib/sidebar/sidebarDatabaseStorage";import { sidebarScrollbarGeometry as calculateSidebarScrollbarGeometry } from "@/lib/sidebar/sidebarScrollbar";import { createSidebarLayoutMonitor, type SidebarExpandedConnectionInfo } from "@/lib/sidebar/sidebarLayoutMonitor";@@ -794,10 +796,30 @@ const sidebarTableNameDisplayTypes = new Set<TreeNodeType>(["table", "view", "maconst sidebarStorageDisplayTypes = new Set<TreeNodeType>(["database", "table", "materialized_view"]);function sidebarCommentLabel(node: TreeNode): string {- const label = sidebarTableNameDisplayTypes.has(node.type) ? sidebarDisplayTableName(node.label, settingsStore.editorSettings.sidebarHiddenTablePrefixes) : node.label;+ const label = sidebarTableNameDisplayTypes.has(node.type) ? sidebarDisplayTableName(node.label, settingsStore.editorSettings.sidebarHiddenTablePrefixes) : sidebarTreeDisplayLabel(node, t, node.connectionId ? effectiveDatabaseTypeForConnection(store.getConfig(node.connectionId)) : undefined);return node.valid === false ? `${label} · INVALID` : label;}+// Shared by the aligned comment column and the full horizontal content width.+// Pin controls are reserved separately so unpinned siblings stay aligned too.+const sidebarTreeLeadingWidthItems = computed(() =>+ flatNodes.value.map(({ id, depth, node }) => {+ const config = node.connectionId ? store.getConfig(node.connectionId) : undefined;+ const badges: string[] = [];+ if (node.type === "column" && node.meta) badges.push(t((node.meta as ColumnInfo).is_nullable ? "structureEditor.nullable" : "structureEditor.notNull"));+ if (["database", "redis-db", "mongo-db"].includes(node.type) && node.connectionId && typeof node.database === "string" && store.isDefaultDatabase(node.connectionId, node.database)) badges.push(t("editor.defaultDatabase"));+ if (node.type === "schema" && node.connectionId && node.schema && store.isDefaultSchema(node.connectionId, node.schema)) badges.push(t("editor.defaultSchema"));+ if (showSidebarRowProductionBadge(node, config) && isSidebarProductionContainer(node)) badges.push("PROD");+ const secondary = sidebarTreeSecondaryValue(node, t);+ const leadingExtraWidth = (secondary && node.type === "elasticsearch-index" ? 16 : 0) + (node.type === "oracle-db-links" ? 26 : 0);+ return { id, depth, node, label: sidebarCommentLabel(node), badges, secondary, leadingExtraWidth };+ }),+);++function measureSidebarTreeLeadingWidth(item: (typeof sidebarTreeLeadingWidthItems.value)[number], context: CanvasRenderingContext2D): number {+ return context.measureText(item.label).width + item.leadingExtraWidth + item.badges.reduce((width, badge) => width + context.measureText(badge).width + 24, 0) + (item.secondary ? context.measureText(item.secondary).width + 8 : 0);+}+function measureSidebarCommentLabelWidths() {sidebarCommentMeasureFrame = 0;if (settingsStore.editorSettings.sidebarObjectInfoMode !== "comment-aligned" || typeof document === "undefined" || !rootRef.value) {@@ -814,12 +836,14 @@ function measureSidebarCommentLabelWidths() {const notNullBadgeWidth = context.measureText(t("structureEditor.notNull")).width + badgePaddingAndGapWidth;context.font = style.font || `${style.fontWeight} ${style.fontSize} ${style.fontFamily}`;sidebarCommentLabelWidths.value = alignedSidebarCommentLabelWidths(- flatNodes.value.map(({ id, depth, node }) => ({- id,- depth,- alignable: isSidebarCommentAlignableNode(node),- hasComment: !!sidebarTreeNodeComment(node, settingsStore.editorSettings.sidebarShowConnectionNotes),- labelWidth: context.measureText(sidebarCommentLabel(node)).width + (node.type === "column" && node.meta ? ((node.meta as ColumnInfo).is_nullable ? nullableBadgeWidth : notNullBadgeWidth) : 0),+ sidebarTreeLeadingWidthItems.value.map((item) => ({+ id: item.id,+ depth: item.depth,+ alignable: isSidebarCommentAlignableNode(item.node),+ hasComment: !!sidebarTreeNodeComment(item.node, settingsStore.editorSettings.sidebarShowConnectionNotes),+ labelWidth: settingsStore.editorSettings.sidebarAllowHorizontalScroll+ ? measureSidebarTreeLeadingWidth(item, context)+ : context.measureText(item.label).width + (item.node.type === "column" && item.node.meta ? ((item.node.meta as ColumnInfo).is_nullable ? nullableBadgeWidth : notNullBadgeWidth) : 0),})),);}@@ -833,19 +857,38 @@ function scheduleSidebarCommentLabelMeasure() {sidebarCommentMeasureFrame = window.requestAnimationFrame(measureSidebarCommentLabelWidths);}-function sidebarNodeHasTrailingMetadata(node: TreeNode): boolean {- const mode = settingsStore.editorSettings.sidebarObjectInfoMode;- if (mode.startsWith("comment-") && sidebarTreeNodeComment(node, settingsStore.editorSettings.sidebarShowConnectionNotes)) return true;- return (mode === "size" || mode === "comment-and-size") && sidebarStorageDisplayTypes.has(node.type) && !!formatSidebarObjectStorage(node.sizeBytes);-}-+// Describe every expanded row, including those outside the virtual viewport.+// Keep text measurement independent of mounted TreeItems so scrolling cannot+// change the horizontal range or truncate a newly materialized row.const sidebarTreeNaturalWidthItems = computed(() =>- flatNodes.value.map(({ depth, node }) => ({- depth,- label: sidebarCommentLabel(node),- usesNaturalWidth: usesFullWidthTreeLabel(node.type, settingsStore.editorSettings.sidebarAllowHorizontalScroll, sidebarNodeHasTrailingMetadata(node)),- trailingWidth: node.pinned || store.isTreeNodePinned(node) ? 20 : 0,- })),+ sidebarTreeLeadingWidthItems.value.map((item) => {+ const { depth, node } = item;+ const mode = settingsStore.editorSettings.sidebarObjectInfoMode;+ const comment = mode.startsWith("comment-") ? (sidebarTreeNodeComment(node, settingsStore.editorSettings.sidebarShowConnectionNotes) ?? undefined) : undefined;+ const config = node.connectionId ? store.getConfig(node.connectionId) : undefined;+ const badges = [...item.badges];+ const leadingExtraWidth = item.leadingExtraWidth + (node.pinned || store.isTreeNodePinned(node) ? sidebarPinnedActionSlotWidthPx : 0);+ let trailingWidth = showSidebarRowProductionBadge(node, config) && !isSidebarProductionContainer(node) ? 24 : 0;+ // Reserve status/control slots regardless of transient connected/loading+ // state, avoiding horizontal jumps when a connection changes status.+ if (node.type === "database") trailingWidth += 14;+ if (node.type === "connection") {+ trailingWidth += 38;+ if (config?.read_only) badges.push(t("connection.readOnlyBadge"));+ }+ return {+ ...item,+ depth,+ usesNaturalWidth: usesFullWidthTreeLabel(node.type, settingsStore.editorSettings.sidebarAllowHorizontalScroll),+ comment,+ rightAlignedComment: mode === "comment-right",+ trailingText: (mode === "size" || mode === "comment-and-size") && sidebarStorageDisplayTypes.has(node.type) ? formatSidebarObjectStorage(node.sizeBytes) : undefined,+ trailingWidth,+ leadingExtraWidth,+ badges,+ alignedWidth: comment && mode === "comment-aligned" && node.type !== "connection" ? (sidebarCommentLabelWidths.value.get(node.id) ?? 0) + (canTreeNodePin(node.type) ? sidebarPinnedActionSlotWidthPx : 0) : 0,+ };+ }),);function measureSidebarTreeContentWidth() {@@ -859,7 +902,15 @@ function measureSidebarTreeContentWidth() {if (!context) return;const style = window.getComputedStyle(rootRef.value);context.font = style.font || `${style.fontWeight} ${style.fontSize} ${style.fontFamily}`;- sidebarTreeContentWidth.value = sidebarTreeNaturalContentWidth(sidebarTreeNaturalWidthItems.value, (text) => context.measureText(text).width, settingsStore.editorSettings.sidebarIndent);+ sidebarTreeContentWidth.value = sidebarTreeNaturalContentWidth(+ sidebarTreeNaturalWidthItems.value.map((item) => ({+ ...item,+ leadingWidth: Math.max(item.alignedWidth, measureSidebarTreeLeadingWidth(item, context)),+ })),+ (text) => context.measureText(text).width,+ settingsStore.editorSettings.sidebarIndent,+ );+ syncStickyRowHorizontalPosition();void nextTick(scheduleSidebarScrollMetricsUpdate);}@@ -874,8 +925,9 @@ function scheduleSidebarTreeContentWidthMeasure() {watch([- flatNodes,+ sidebarTreeLeadingWidthItems,locale,+ () => settingsStore.editorSettings.sidebarAllowHorizontalScroll,() => settingsStore.editorSettings.sidebarObjectInfoMode,() => settingsStore.editorSettings.sidebarShowConnectionNotes,() => settingsStore.editorSettings.sidebarHiddenTablePrefixes,@@ -1005,6 +1057,7 @@ watch(const stickyScrollTop = ref(0);const plainStickyContainerIndex = ref(-1);const sidebarScrollMetrics = ref({ scrollTop: 0, scrollLeft: 0, clientHeight: 0, clientWidth: 0, scrollHeight: 0, scrollWidth: 0 });+const stickyRowRef = ref<HTMLElement | null>(null);const isScrollingSidebar = ref(false);const isDraggingSidebarScrollbar = ref(false);const isDraggingSidebarHorizontalScrollbar = ref(false);@@ -1018,6 +1071,7 @@ function updateSidebarScrollMetrics() {const scroller = currentTreeScroller();if (!scroller) {sidebarScrollMetrics.value = { scrollTop: 0, scrollLeft: 0, clientHeight: 0, clientWidth: 0, scrollHeight: 0, scrollWidth: 0 };+ syncStickyRowHorizontalPosition(null);return;}@@ -1035,8 +1089,9 @@ function updateSidebarScrollMetrics() {clientHeight: scroller.clientHeight,clientWidth: scroller.clientWidth,scrollHeight: scroller.scrollHeight,- scrollWidth: Math.max(scroller.scrollWidth, sidebarTreeContentWidth.value),+ scrollWidth: scroller.scrollWidth,};+ syncStickyRowHorizontalPosition(scroller);}function scheduleSidebarScrollMetricsUpdate() {@@ -1050,6 +1105,31 @@ function onTreeScroll() {sidebarScrollingTimer = window.setTimeout(() => {isScrollingSidebar.value = false;}, 700);+ syncStickyRowHorizontalPosition();+ scheduleSidebarScrollMetricsUpdate();+}++function onTreeWheel(event: WheelEvent) {+ const scroller = currentTreeScroller();+ if (!scroller || !settingsStore.editorSettings.sidebarAllowHorizontalScroll || !event.shiftKey) return;+ if (event.target instanceof Element && event.target.closest("input, textarea, select, [contenteditable=true]")) return;+ const delta = sidebarHorizontalWheelDelta({+ enabled: true,+ shiftKey: event.shiftKey,+ deltaX: event.deltaX,+ deltaY: event.deltaY,+ deltaMode: event.deltaMode,+ lineHeight: sidebarTreeRowHeight.value,+ scrollLeft: scroller.scrollLeft,+ clientWidth: scroller.clientWidth,+ scrollWidth: scroller.scrollWidth,+ });+ if (delta === 0) return;+ const previous = scroller.scrollLeft;+ scroller.scrollLeft += delta;+ if (scroller.scrollLeft === previous) return;+ syncStickyRowHorizontalPosition(scroller);+ event.preventDefault();scheduleSidebarScrollMetricsUpdate();}@@ -1142,6 +1222,28 @@ const stickyTableSearchScope = computed(() => {return scope;});const stickyTableSearchNode = computed(() => stickyTableSearchScope.value?.item ?? null);++function syncStickyRowHorizontalPosition(scroller = currentTreeScroller()) {+ const row = stickyRowRef.value;+ if (!row) return;++ if (!settingsStore.editorSettings.sidebarAllowHorizontalScroll || !scroller) {+ row.style.removeProperty("width");+ row.style.removeProperty("transform");+ return;+ }++ row.style.width = `${Math.max(scroller.clientWidth, sidebarTreeContentWidth.value)}px`;+ row.style.transform = `translate3d(${-scroller.scrollLeft}px, 0, 0)`;+}++watch(+ [stickyNode, useVirtualTree, treeScrollerRef, plainTreeScrollerRef],+ () => {+ void nextTick(() => syncStickyRowHorizontalPosition());+ },+ { flush: "post", immediate: true },+);const stickyHeaderHeight = computed(() => sidebarTreeRowHeight.value * (stickyTableSearchNode.value ? 2 : 1));const stickyHeaderStyle = computed<CSSProperties>(() => {@@ -1241,6 +1343,7 @@ watch(void nextTick(() => {const scroller = currentTreeScroller();if (!enabled && scroller) scroller.scrollLeft = 0;+ syncStickyRowHorizontalPosition(scroller);scheduleSidebarScrollMetricsUpdate();}),{ flush: "post" },@@ -1350,6 +1453,7 @@ function setSidebarHorizontalScrollFromPointer(clientX: number, offset: number)const thumbLeft = Math.min(maxThumbLeft, Math.max(0, clientX - rect.left - offset));scroller.scrollLeft = (thumbLeft / maxThumbLeft) * maxScrollLeft;+ syncStickyRowHorizontalPosition(scroller);updateSidebarScrollMetrics();}@@ -2778,6 +2882,7 @@ defineExpose({:class="sidebarTreeOverflowClass":style="sidebarTreeScrollerStyle"@click="clearSidebarSelection"+ @wheel="onTreeWheel":items="flatNodes":item-size="sidebarTreeRowHeight":buffer="SIDEBAR_TREE_SCROLL_BUFFER"@@ -2803,15 +2908,17 @@ defineExpose({</template></RecycleScroller><div v-if="stickyNode" class="sticky-database-header pointer-events-auto absolute inset-x-0 top-0 z-[5]" :style="stickyHeaderStyle">- <TreeItem- :node="stickyNode.node"- :depth="stickyNode.depth"- :reorder-disabled="true"- :reference-drag-disabled="true"- :comment-label-width="sidebarCommentLabelWidths.get(stickyNode.node.id)"- :is-sticky-context="stickyProductionContext"- @context-menu="(event, node) => openSidebarContextMenu(event, node, contextMenuSlot.onContextMenu)"- />+ <div ref="stickyRowRef">+ <TreeItem+ :node="stickyNode.node"+ :depth="stickyNode.depth"+ :reorder-disabled="true"+ :reference-drag-disabled="true"+ :comment-label-width="sidebarCommentLabelWidths.get(stickyNode.node.id)"+ :is-sticky-context="stickyProductionContext"+ @context-menu="(event, node) => openSidebarContextMenu(event, node, contextMenuSlot.onContextMenu)"+ />+ </div><TreeItem v-if="stickyTableSearchNode" :key="stickyTableSearchNode.renderKey" :node="stickyTableSearchNode.node" :depth="stickyTableSearchNode.depth" :reorder-disabled="true" :reference-drag-disabled="true" /></div><div v-if="stickyProductionContext" class="sidebar-sticky-production" :style="{ height: `${sidebarTreeRowHeight}px` }">@@ -2837,7 +2944,7 @@ defineExpose({</div></div><div v-else-if="flatNodes.length > 0" ref="treeScrollShellRef" class="connection-tree-scroll-shell relative min-h-0 flex-1" :class="{ 'connection-tree-scroll-shell--horizontal-overflow': hasSidebarHorizontalOverflow }">- <div ref="plainTreeScrollerRef" class="sidebar-tree connection-tree-scroller h-full overflow-y-auto" :class="sidebarTreeOverflowClass" :style="sidebarTreeScrollerStyle" @click="clearSidebarSelection" @scroll.passive="onTreeScroll">+ <div ref="plainTreeScrollerRef" class="sidebar-tree connection-tree-scroller h-full overflow-y-auto" :class="sidebarTreeOverflowClass" :style="sidebarTreeScrollerStyle" @click="clearSidebarSelection" @wheel="onTreeWheel" @scroll.passive="onTreeScroll"><div class="connection-tree-content"><TreeItemv-for="item in flatNodes"@@ -2856,15 +2963,17 @@ defineExpose({</div></div><div v-if="stickyNode" class="sticky-database-header pointer-events-auto absolute inset-x-0 top-0 z-[5]" :style="stickyHeaderStyle">- <TreeItem- :node="stickyNode.node"- :depth="stickyNode.depth"- :reorder-disabled="true"- :reference-drag-disabled="true"- :comment-label-width="sidebarCommentLabelWidths.get(stickyNode.node.id)"- :is-sticky-context="stickyProductionContext"- @context-menu="(event, node) => openSidebarContextMenu(event, node, contextMenuSlot.onContextMenu)"- />+ <div ref="stickyRowRef">+ <TreeItem+ :node="stickyNode.node"+ :depth="stickyNode.depth"+ :reorder-disabled="true"+ :reference-drag-disabled="true"+ :comment-label-width="sidebarCommentLabelWidths.get(stickyNode.node.id)"+ :is-sticky-context="stickyProductionContext"+ @context-menu="(event, node) => openSidebarContextMenu(event, node, contextMenuSlot.onContextMenu)"+ />+ </div><TreeItem v-if="stickyTableSearchNode" :key="stickyTableSearchNode.renderKey" :node="stickyTableSearchNode.node" :depth="stickyTableSearchNode.depth" :reorder-disabled="true" :reference-drag-disabled="true" /></div><div v-if="stickyProductionContext" class="sidebar-sticky-production" :style="{ height: `${sidebarTreeRowHeight}px` }">@@ -3057,11 +3166,15 @@ defineExpose({overlap the next row. Pin every materialized row to the fixed height and clipany overflow instead of letting the layout drift. */height: var(--sidebar-tree-row-height, 28px);- overflow: hidden;+ overflow: clip;}.connection-tree-scroller.sidebar-tree-horizontal-scroll :deep(.vue-recycle-scroller__item-view) {width: max-content;+ /* Viewport-sized controls move within this row when scrolling horizontally.+ Keep the clipping wrapper as wide as the content so it cannot cut them+ off, and let ordinary row backgrounds cover the full scrollable width. */+ min-width: max(100%, var(--sidebar-tree-content-width));}.connection-tree-scroller.sidebar-tree-horizontal-scroll :deep(.connection-tree-content),@@ -3069,6 +3182,19 @@ defineExpose({min-width: max(100%, var(--sidebar-tree-content-width));}+.connection-tree-scroller.sidebar-tree-horizontal-scroll :deep(.tree-table-search-control),+.connection-tree-scroller.sidebar-tree-horizontal-scroll :deep(.tree-row-viewport) {+ /* These rows may scroll with the tree, but their connection tint must span+ the entire horizontal content range so no white strip appears at the+ right edge after scrolling. */+ width: max(100%, var(--sidebar-tree-content-width));+}++.connection-tree-scroller.sidebar-tree-horizontal-scroll :deep(.tree-table-search-control__content) {+ width: 100cqw;+ min-width: 100cqw;+}+.connection-tree-scroll-shell--horizontal-overflow .connection-tree-scroller {height: calc(100% - 10px);}diff --git a/apps/desktop/src/components/sidebar/TreeItem.vue b/apps/desktop/src/components/sidebar/TreeItem.vueindex 9b4d07a8ca..193fe5f75d 100644--- a/apps/desktop/src/components/sidebar/TreeItem.vue+++ b/apps/desktop/src/components/sidebar/TreeItem.vue@@ -56,8 +56,20 @@ import { Badge } from "@/components/ui/badge";import { Input } from "@/components/ui/input";import { Switch } from "@/components/ui/switch";import LightTooltip from "@/components/ui/LightTooltip.vue";-import type { ColumnInfo, CustomTypeTreeMemberMeta, DatabaseType, TreeNode, TriggerInfo } from "@/types/database";-import { alignedCommentLeadingWidth, canTreeNodePin, canTreeNodeShowExpander, isSidebarCommentSupportedType, sidebarTreeNodeComment, trailingCommentAvailableWidth, trailingCommentGapPx, treeItemPaddingLeft, treeLabelWidthClass, usesFullWidthTreeLabel } from "@/lib/sidebar/sidebarTreeItemLayout";+import type { ColumnInfo, DatabaseType, TreeNode, TriggerInfo } from "@/types/database";+import {+ alignedCommentLeadingWidth,+ canTreeNodePin,+ canTreeNodeShowExpander,+ isSidebarCommentSupportedType,+ sidebarTreeNodeComment,+ trailingCommentAvailableWidth,+ trailingCommentGapPx,+ sidebarRightCommentMaxWidthPx,+ treeItemPaddingLeft,+ treeLabelWidthClass,+ usesFullWidthTreeLabel,+} from "@/lib/sidebar/sidebarTreeItemLayout";import {clearActiveTableReferencePayload,createColumnReferencePayload,@@ -100,13 +112,13 @@ import { ensureSqlExtension, stripSqlExtension } from "@/lib/savedSql/savedSqlFiimport { savedSqlErrorMessage } from "@/lib/savedSql/savedSqlErrors";import { useSavedSqlStore } from "@/stores/savedSqlStore";import { elasticsearchIndexAliasLabel } from "@/lib/sidebar/elasticsearchIndexActions";-import { isXuguPublicSynonymTreeNode, isXuguSchedulerJobTreeNode, xuguSchemaDisplayName } from "@/lib/sidebar/xuguPublicSynonyms";+import { isXuguPublicSynonymTreeNode, isXuguSchedulerJobTreeNode } from "@/lib/sidebar/xuguPublicSynonyms";import { xuguDatafileDetailRows, xuguTablespaceDetailRows } from "@/lib/sidebar/xuguTablespaces";// --- Drag and Drop ---import { useDragSort } from "@/composables/useDragSort";import { sidebarTreeRuntimeKey } from "@/lib/sidebar/sidebarTreeRuntime";import { treeNodePinKey } from "@/lib/app/pinnedItems";-import { isTreeGroupNodeType } from "@/lib/sidebar/treeNodeGroup";+import { sidebarTreeDisplayLabel, sidebarTreeSecondaryValue } from "@/lib/sidebar/sidebarTreeLabel";import { customTypeCapabilities } from "@/lib/database/databaseObjectCapabilities";import { shouldActivateTreeNodeOnSingleClick } from "@/lib/sidebar/treeNodeClick";@@ -448,37 +460,12 @@ function getIconInfo(node: TreeNode): { icon: any; colorClass: string } | null {}}-function isGroupLabel(node: TreeNode): boolean {- return isTreeGroupNodeType(node.type);-}-function displayLabel(node: TreeNode): string {- // Synthetic Xugu scopes are persisted with their reserved protocol value.- // Resolve them at render time as well, so an already-cached tree never- // exposes that implementation detail after the feature is introduced.- if (node.type === "schema" && node.connectionId) {- const databaseType = effectiveDatabaseTypeForConnection(connectionStore.getConfig(node.connectionId));- if (databaseType === "xugu") return xuguSchemaDisplayName(node.schema ?? node.label);- }- if (node.type === "load-more") return t(node.label);- if (node.type === "object-browser") return t(node.label, { count: node.objectCount ?? 0 });- // Use the canonical key for persisted trees created before this label was- // internationalized; those nodes may still contain the old Chinese text.- if (node.type === "nacos-access-control") return t("nacos.accessControlSidebarLabel");- if (node.type === "user-admin" || node.type === "xugu-user-admin" || node.type === "dameng-users" || node.type === "dameng-roles" || node.type === "dameng-job-admin" || node.type === "meilisearch-system") return t(node.label);- if (node.type === "oracle-db-links" || node.type === "linked-server-root") return t(node.label);- if (node.type === "saved-sql-root") return t(node.label);- if (node.type === "mqtt-topic" && node.id.endsWith(":mqtt-topic:__console__")) return t(node.label);- if (node.label === "tree.defaultDatabase") return t(node.label);- return isGroupLabel(node) ? t(node.label) : node.label;+ return sidebarTreeDisplayLabel(node, t, node.connectionId ? effectiveDatabaseTypeForConnection(connectionStore.getConfig(node.connectionId)) : undefined);}function treeNodeSecondaryValue(node: TreeNode): string | undefined {- if (node.type === "type" && node.customTypeKind) return t(`customType.kinds.${node.customTypeKind}`);- if (node.type === "type-member") return (node.meta as CustomTypeTreeMemberMeta | undefined)?.displayValue;- if (node.type === "datafile") return node.xuguDatafilePath;- if (node.type === "elasticsearch-index") return elasticsearchIndexAliasLabel(node);- return undefined;+ return sidebarTreeSecondaryValue(node, t);}function visibleLabel(node: TreeNode): string {@@ -837,7 +824,7 @@ function measureTrailingCommentLayout() {trailingCommentMaxWidth.value = 0;return;}- trailingCommentMaxWidth.value = trailingCommentAvailableWidth(container.clientWidth, leading.scrollWidth);+ trailingCommentMaxWidth.value = settingsStore.editorSettings.sidebarAllowHorizontalScroll ? sidebarRightCommentMaxWidthPx : trailingCommentAvailableWidth(container.clientWidth, leading.scrollWidth);}function scheduleTrailingCommentMeasure() {@@ -882,7 +869,7 @@ function formattedObjectStorage(): string {const alignedCommentLabelWidth = computed(() => (settingsStore.editorSettings.sidebarObjectInfoMode === "comment-aligned" && activeNode.value.type !== "connection" ? props.commentLabelWidth : undefined));function alignedCommentLeadingStyle(): { width: string } | { maxWidth: string } | undefined {- if (settingsStore.editorSettings.sidebarObjectInfoMode === "comment-and-size" && trailingComment.value) {+ if (!settingsStore.editorSettings.sidebarAllowHorizontalScroll && settingsStore.editorSettings.sidebarObjectInfoMode === "comment-and-size" && trailingComment.value) {// Reserve the inline comment's margin so a long name cannot push into the size column.return { maxWidth: "max(0px, calc(100% - 1rem))" };}@@ -898,7 +885,7 @@ const usesFullWidthLabel = computed(() => usesFullWidthTreeLabel(activeNode.valuconst isCompactSidebar = computed(() => settingsStore.editorSettings.sidebarDensity === "compact");-const rowWidthClass = computed(() => (usesFullWidthLabel.value ? "w-max min-w-full" : "w-full min-w-0"));+const rowWidthClass = computed(() => (usesFullWidthLabel.value ? "w-max min-w-full" : "w-full min-w-0 tree-row-viewport"));const labelWidthClass = computed(() => {// aligned 模式靠 leading 块固定宽度对齐 comment 列,label 需 flex-1 撑满 leading 块;@@ -908,7 +895,7 @@ const labelWidthClass = computed(() => {return treeLabelWidthClass({ fullWidth: usesFullWidthLabel.value, hasTrailingComment: hasTrailingMetadata(), hasInlineAction: isPinned.value, alignLeading });});-watch(() => [isRightAlignedComment(), visibleLabel(activeNode.value), trailingComment.value, trailingCommentLayoutRef.value, trailingCommentLeadingRef.value], refreshTrailingCommentMeasurement, { flush: "post", immediate: true });+watch(() => [settingsStore.editorSettings.sidebarAllowHorizontalScroll, isRightAlignedComment(), visibleLabel(activeNode.value), trailingComment.value, trailingCommentLayoutRef.value, trailingCommentLeadingRef.value], refreshTrailingCommentMeasurement, { flush: "post", immediate: true });const paddingLeft = computed(() => treeItemPaddingLeft(props.depth, settingsStore.editorSettings.sidebarIndent));@@ -1566,44 +1553,36 @@ function onKeydown(event: KeyboardEvent) {</script><template>- <div- v-if="node.type === 'table-search-control'"- data-sidebar-table-search-control- class="tree-table-search-control flex items-center gap-1.5 pr-2"- :class="isCompactSidebar ? 'h-6 py-0' : 'h-7 py-0.5'"- :style="tableSearchStyle"- @click.stop- @dblclick.stop- @mousedown.stop- @keydown="onTableSearchControlKeydown"- >- <div class="relative min-w-0 flex-1">- <Search class="pointer-events-none absolute left-2 top-1/2 h-3 w-3 -translate-y-1/2 text-muted-foreground" />- <Input- :model-value="tableSearchValue"- autocapitalize="off"- autocorrect="off"- spellcheck="false"- class="w-full rounded border pl-7 pr-6 text-xs shadow-none focus-visible:ring-1"- :class="isCompactSidebar ? 'h-5' : 'h-6'"- :style="{ backgroundColor: 'var(--tree-table-search-input-bg)', borderColor: 'var(--tree-table-search-border)' }"- :placeholder="t(node.label)"- :aria-label="t(node.label)"- :data-sidebar-table-search-parent-id="tableSearchParentId"- @update:model-value="updateTableSearchQuery"- />- <button v-if="tableSearchValue" type="button" class="absolute right-1.5 top-1/2 flex h-4 w-4 -translate-y-1/2 items-center justify-center rounded text-muted-foreground hover:bg-muted hover:text-foreground" :aria-label="t('sidebar.clearTableSearch')" @click.stop="clearTableSearchQuery">- <X class="h-3 w-3" />- </button>+ <div v-if="node.type === 'table-search-control'" data-sidebar-table-search-control class="tree-table-search-control pr-2" :class="isCompactSidebar ? 'h-6 py-0' : 'h-7 py-0.5'" :style="tableSearchStyle" @click.stop @dblclick.stop @mousedown.stop @keydown="onTableSearchControlKeydown">+ <div class="tree-table-search-control__content flex w-full min-w-0 items-center gap-1.5">+ <div class="relative min-w-0 flex-1">+ <Search class="pointer-events-none absolute left-2 top-1/2 h-3 w-3 -translate-y-1/2 text-muted-foreground" />+ <Input+ :model-value="tableSearchValue"+ autocapitalize="off"+ autocorrect="off"+ spellcheck="false"+ class="w-full rounded border pl-7 pr-6 text-xs shadow-none focus-visible:ring-1"+ :class="isCompactSidebar ? 'h-5' : 'h-6'"+ :style="{ backgroundColor: 'var(--tree-table-search-input-bg)', borderColor: 'var(--tree-table-search-border)' }"+ :placeholder="t(node.label)"+ :aria-label="t(node.label)"+ :data-sidebar-table-search-parent-id="tableSearchParentId"+ @update:model-value="updateTableSearchQuery"+ />+ <button v-if="tableSearchValue" type="button" class="absolute right-1.5 top-1/2 flex h-4 w-4 -translate-y-1/2 items-center justify-center rounded text-muted-foreground hover:bg-muted hover:text-foreground" :aria-label="t('sidebar.clearTableSearch')" @click.stop="clearTableSearchQuery">+ <X class="h-3 w-3" />+ </button>+ </div>+ <LightTooltip :text="t('sidebar.localTableSearchTooltip')" side="top" :delay="300">+ <Switch size="sm" :model-value="settingsStore.editorSettings.sidebarTableSearchLocal" :aria-label="t('sidebar.localTableSearch')" @update:model-value="updateTableSearchLocal(Boolean($event))" />+ </LightTooltip>+ <LightTooltip v-if="settingsStore.editorSettings.sidebarTableSearchLocal" :text="t('sidebar.refreshLocalTableSearchIndex')" side="top" :delay="300">+ <button type="button" class="flex h-5 w-5 shrink-0 items-center justify-center rounded text-muted-foreground hover:bg-muted hover:text-foreground" :aria-label="t('sidebar.refreshLocalTableSearchIndex')" @click.stop="refreshTableSearchIndex">+ <RefreshCw class="h-3 w-3" />+ </button>+ </LightTooltip></div>- <LightTooltip :text="t('sidebar.localTableSearchTooltip')" side="top" :delay="300">- <Switch size="sm" :model-value="settingsStore.editorSettings.sidebarTableSearchLocal" :aria-label="t('sidebar.localTableSearch')" @update:model-value="updateTableSearchLocal(Boolean($event))" />- </LightTooltip>- <LightTooltip v-if="settingsStore.editorSettings.sidebarTableSearchLocal" :text="t('sidebar.refreshLocalTableSearchIndex')" side="top" :delay="300">- <button type="button" class="flex h-5 w-5 shrink-0 items-center justify-center rounded text-muted-foreground hover:bg-muted hover:text-foreground" :aria-label="t('sidebar.refreshLocalTableSearchIndex')" @click.stop="refreshTableSearchIndex">- <RefreshCw class="h-3 w-3" />- </button>- </LightTooltip></div><div v-else @contextmenu="onTreeItemContextMenu">@@ -1669,8 +1648,15 @@ function onKeydown(event: KeyboardEvent) {<Ban class="h-2.5 w-2.5 stroke-[3]" aria-hidden="true" /></span></span>- <div ref="trailingCommentLayoutRef" :class="[hasTrailingMetadata() ? 'flex flex-1 min-w-0 items-center' : 'contents', { 'overflow-hidden': settingsStore.editorSettings.sidebarObjectInfoMode === 'comment-and-size' }]">- <div ref="trailingCommentLeadingRef" :class="trailingComment ? 'flex max-w-full min-w-0 shrink-0 items-center gap-2' : formattedObjectStorage() ? 'flex min-w-0 flex-1 items-center gap-2' : 'contents'" :style="alignedCommentLeadingStyle()">+ <div+ ref="trailingCommentLayoutRef"+ :class="[hasTrailingMetadata() ? (usesFullWidthLabel ? 'flex min-w-max flex-1 items-center' : 'flex flex-1 min-w-0 items-center') : 'contents', { 'overflow-hidden': !usesFullWidthLabel && settingsStore.editorSettings.sidebarObjectInfoMode === 'comment-and-size' }]"+ >+ <div+ ref="trailingCommentLeadingRef"+ :class="trailingComment ? (usesFullWidthLabel ? 'flex min-w-0 shrink-0 items-center gap-2' : 'flex max-w-full min-w-0 shrink-0 items-center gap-2') : formattedObjectStorage() ? 'flex min-w-0 flex-1 items-center gap-2' : 'contents'"+ :style="alignedCommentLeadingStyle()"+ ><inputv-if="isRenamingGroup || isRenamingSavedSql || isRenamingConnection"ref="renameInputRef"@@ -1706,7 +1692,7 @@ function onKeydown(event: KeyboardEvent) {<button v-if="node.type === 'oracle-db-links'" class="ml-auto rounded p-0.5 text-muted-foreground hover:bg-muted" :aria-label="t('databaseLinks.manage')" :title="t('databaseLinks.manage')" @click.stop="showDatabaseLinks = true" @dblclick.stop><TableProperties class="h-3.5 w-3.5" /></button>- <span v-if="treeNodeSecondaryValue(node)" class="flex min-w-0 max-w-[55%] shrink items-center gap-1 text-xs text-muted-foreground" :title="node.type === 'elasticsearch-index' ? undefined : treeNodeSecondaryValue(node)">+ <span v-if="treeNodeSecondaryValue(node)" class="flex min-w-0 items-center gap-1 text-xs text-muted-foreground" :class="usesFullWidthLabel ? 'shrink-0' : 'max-w-[55%] shrink'" :title="node.type === 'elasticsearch-index' ? undefined : treeNodeSecondaryValue(node)"><Link2 v-if="node.type === 'elasticsearch-index'" class="h-3 w-3 shrink-0 text-sky-400" /><span class="min-w-0 truncate">{{ treeNodeSecondaryValue(node) }}</span></span>@@ -1762,7 +1748,7 @@ function onKeydown(event: KeyboardEvent) {{{ t("editor.defaultSchema") }}</Badge></div>- <span v-if="trailingComment && !isRightAlignedComment()" class="sidebar-object-comment ml-4 min-w-0 flex-1 truncate text-left" :class="{ 'sidebar-object-comment--windows': useWindowsSidebarCommentFont }">{{ trailingComment }}</span>+ <span v-if="trailingComment && !isRightAlignedComment()" class="sidebar-object-comment ml-4 min-w-0 flex-1 truncate text-left" :class="{ 'sidebar-object-comment--windows': useWindowsSidebarCommentFont, 'sidebar-object-comment--horizontal': usesFullWidthLabel }">{{ trailingComment }}</span><span v-if="isRightAlignedComment() && trailingCommentMaxWidth > 0" class="min-w-0 flex-1" aria-hidden="true" /><spanv-if="isRightAlignedComment() && trailingCommentMaxWidth > 0"@@ -1853,6 +1839,14 @@ function onKeydown(event: KeyboardEvent) {flex-shrink: 999;}+.sidebar-object-comment--horizontal {+ flex: 0 0 auto;+ min-width: max-content;+ max-width: none;+ overflow: visible;+ white-space: nowrap;+}+.sidebar-object-comment--windows {font-family: "Microsoft YaHei UI", "Microsoft YaHei", "Segoe UI", system-ui, sans-serif;font-size: 1em;diff --git a/apps/desktop/src/components/sidebar/__tests__/ConnectionTree.commentAlignment.spec.ts b/apps/desktop/src/components/sidebar/__tests__/ConnectionTree.commentAlignment.spec.tsindex 3892363f03..39532c56b0 100644--- a/apps/desktop/src/components/sidebar/__tests__/ConnectionTree.commentAlignment.spec.ts+++ b/apps/desktop/src/components/sidebar/__tests__/ConnectionTree.commentAlignment.spec.ts@@ -1,7 +1,7 @@import { readFileSync } from "node:fs";import ts from "typescript";import { parse } from "vue/compiler-sfc";-import { nextTick, reactive, ref, shallowRef, watch } from "vue";+import { computed, nextTick, reactive, ref, shallowRef, watch } from "vue";import { describe, expect, it, vi } from "vitest";import en from "@/i18n/locales/en";import es from "@/i18n/locales/es";@@ -12,11 +12,14 @@ import ptBR from "@/i18n/locales/pt-BR";import zhCN from "@/i18n/locales/zh-CN";import zhTW from "@/i18n/locales/zh-TW";import { alignedSidebarCommentLabelWidths, isSidebarCommentAlignableNode, sidebarTreeNodeComment } from "@/lib/sidebar/sidebarTreeItemLayout";+import { sidebarTreeSecondaryValue } from "@/lib/sidebar/sidebarTreeLabel";+import { showSidebarRowProductionBadge, isSidebarProductionContainer } from "@/lib/sidebar/sidebarProductionBadge";import type { ColumnInfo, TreeNode } from "@/types/database";const source = parse(readFileSync(new URL("../ConnectionTree.vue", import.meta.url), "utf8")).descriptor.scriptSetup!.content;const script = ts.createSourceFile("ConnectionTree.ts", source, ts.ScriptTarget.Latest, true);const measureStatement = script.statements.find((statement) => ts.isFunctionDeclaration(statement) && statement.name?.text === "measureSidebarCommentLabelWidths")!.getText(script);+const leadingStatement = script.statements.find((statement) => ts.isVariableStatement(statement) && statement.declarationList.declarations.some((declaration) => declaration.name.getText(script) === "sidebarTreeLeadingWidthItems"))!.getText(script);const watchStatement = script.statements.find((statement) => ts.isExpressionStatement(statement) && ts.isCallExpression(statement.expression) && statement.expression.expression.getText(script) === "watch" && statement.expression.arguments[1]?.getText(script) === "scheduleSidebarCommentLabelMeasure")!.getText(script);@@ -48,7 +51,12 @@ function fixture(nodes: TreeNode[], initialLocale: Locale = "en", mode = "commen}),};const canvas = { getContext: vi.fn((): typeof context | null => context) };- const scope = {+ const bindings = {+ computed,+ store: { getConfig: () => undefined, isDefaultDatabase: () => false, isDefaultSchema: () => false },+ sidebarTreeSecondaryValue,+ showSidebarRowProductionBadge,+ isSidebarProductionContainer,locale,flatNodes: shallowRef(nodes.map((node) => ({ id: node.id, depth: 1, node }))),settingsStore: reactive({ editorSettings: { sidebarObjectInfoMode: mode, sidebarShowConnectionNotes: false, sidebarHiddenTablePrefixes: [], uiFontFamily: "sans-serif", uiScale: 1, sidebarFontSize: 14 } }),@@ -63,6 +71,7 @@ function fixture(nodes: TreeNode[], initialLocale: Locale = "en", mode = "commenisSidebarCommentAlignableNode,sidebarTreeNodeComment,};+ const scope = { ...bindings, sidebarTreeLeadingWidthItems: execute(`${leadingStatement}\nreturn sidebarTreeLeadingWidthItems;`, bindings) };const measure = () => execute(`${measureStatement}\nmeasureSidebarCommentLabelWidths();`, scope);return { scope, measure, measurements, canvas };}diff --git a/apps/desktop/src/components/sidebar/__tests__/ConnectionTree.horizontalScroll.spec.ts b/apps/desktop/src/components/sidebar/__tests__/ConnectionTree.horizontalScroll.spec.tsnew file mode 100644index 0000000000..c4293098e3--- /dev/null+++ b/apps/desktop/src/components/sidebar/__tests__/ConnectionTree.horizontalScroll.spec.ts@@ -0,0 +1,180 @@+// @vitest-environment happy-dom+import { readFileSync } from "node:fs";+import ts from "typescript";+import { parse } from "vue/compiler-sfc";+import { computed, ref } from "vue";+import { describe, expect, it, vi } from "vitest";+import { sidebarHorizontalWheelDelta } from "@/lib/sidebar/sidebarScrollbar";+import { alignedSidebarCommentLabelWidths, isSidebarCommentAlignableNode, canTreeNodePin, sidebarPinnedActionSlotWidthPx, sidebarTreeNaturalContentWidth, sidebarTreeNodeComment, usesFullWidthTreeLabel } from "@/lib/sidebar/sidebarTreeItemLayout";+import { sidebarTreeSecondaryValue } from "@/lib/sidebar/sidebarTreeLabel";+import { showSidebarRowProductionBadge, isSidebarProductionContainer } from "@/lib/sidebar/sidebarProductionBadge";+import { formatSidebarObjectStorage } from "@/lib/sidebar/sidebarDatabaseStorage";+import type { TreeNode } from "@/types/database";++const source = parse(readFileSync("apps/desktop/src/components/sidebar/ConnectionTree.vue", "utf8")).descriptor.scriptSetup!.content;+const script = ts.createSourceFile("ConnectionTree.ts", source, ts.ScriptTarget.Latest, true);+function statement(name: string) {+ return script.statements.find((item) => (ts.isFunctionDeclaration(item) && item.name?.text === name) || (ts.isVariableStatement(item) && item.declarationList.declarations.some((declaration) => declaration.name.getText(script) === name)))!.getText(script);+}+function execute(code: string, bindings: Record<string, unknown>) {+ const compiled = ts.transpileModule(code, { compilerOptions: { target: ts.ScriptTarget.ES2022, module: ts.ModuleKind.CommonJS } }).outputText;+ return new Function(...Object.keys(bindings), compiled)(...Object.values(bindings));+}++function wheel(options: WheelEventInit): WheelEvent {+ const event = new WheelEvent("wheel", { cancelable: true });+ // happy-dom does not initialize all WheelEvent modifier/delta properties.+ for (const [key, value] of Object.entries(options)) Object.defineProperty(event, key, { value, configurable: true });+ return event;+}++function measure(nodes: TreeNode[], mode: string, alignedWidths = new Map<string, number>()) {+ const width = ref(0);+ const context = { font: "", measureText: (text: string) => ({ width: text.length * 7 }) };+ execute(`${statement("sidebarTreeLeadingWidthItems")}\n${statement("measureSidebarTreeLeadingWidth")}\n${statement("sidebarTreeNaturalWidthItems")}\n${statement("measureSidebarTreeContentWidth")}\nmeasureSidebarTreeContentWidth();`, {+ computed,+ flatNodes: ref(nodes.map((node) => ({ node, depth: 3 }))),+ settingsStore: { editorSettings: { sidebarAllowHorizontalScroll: true, sidebarObjectInfoMode: mode, sidebarIndent: 16, sidebarShowConnectionNotes: true } },+ store: { getConfig: () => undefined, isTreeNodePinned: () => false, isDefaultDatabase: () => false, isDefaultSchema: () => false },+ t: (key: string) => key,+ sidebarCommentLabel: (node: TreeNode) => node.label,+ sidebarTreeSecondaryValue,+ showSidebarRowProductionBadge,+ isSidebarProductionContainer,+ sidebarTreeNodeComment,+ usesFullWidthTreeLabel,+ canTreeNodePin,+ sidebarPinnedActionSlotWidthPx,+ sidebarCommentLabelWidths: ref(alignedWidths),+ sidebarStorageDisplayTypes: new Set(["database", "table", "materialized_view"]),+ formatSidebarObjectStorage,+ sidebarTreeContentMeasureFrame: 0,+ rootRef: ref({}),+ sidebarTreeContentWidth: width,+ document: { createElement: () => ({ getContext: () => context }) },+ window: { getComputedStyle: () => ({ font: "400 14px sans-serif" }) },+ sidebarTreeNaturalContentWidth,+ nextTick: () => Promise.resolve(),+ scheduleSidebarScrollMetricsUpdate: vi.fn(),+ syncStickyRowHorizontalPosition: vi.fn(),+ });+ return width.value;+}++describe("ConnectionTree horizontal scrolling", () => {+ it("measures long database and column rows outside the mounted window, including badges and comments", () => {+ const short: TreeNode = { id: "short", type: "table", label: "short" };+ const long: TreeNode = { id: "long", type: "column", label: "long_field_name".repeat(20), meta: { is_nullable: false, comment: "field comment" } as never };+ const shortWidth = measure([short], "comment-inline");+ const all = [short, ...Array.from({ length: 400 }, (_, i) => ({ ...short, id: String(i) })), long];+ expect(measure(all, "comment-inline")).toBeGreaterThan(shortWidth + 1000);+ expect(measure(all, "comment-inline")).toBeGreaterThan(measure(all, "hidden"));+ expect(measure([{ id: "db", type: "database", label: "long_db".repeat(50) }], "hidden")).toBeGreaterThan(2000);+ });++ it("includes an aligned sibling column and bounds right comments", () => {+ const node: TreeNode = { id: "table", type: "table", label: "id", comment: "comment", sizeBytes: 1024 };+ expect(measure([node], "comment-aligned", new Map([[node.id, 600]]))).toBeGreaterThan(measure([node], "comment-inline") + 400);+ expect(measure([{ ...node, comment: "c".repeat(1000) }], "comment-right")).toBe(measure([{ ...node, comment: "c".repeat(2000) }], "comment-right"));+ expect(measure([node], "comment-and-size")).toBeGreaterThan(measure([node], "comment-inline"));+ });++ it("reserves default-schema badges and secondary values before aligned comments, including after settings change", () => {+ const widths = ref(new Map<string, number>());+ const settingsStore = { editorSettings: { sidebarAllowHorizontalScroll: true, sidebarObjectInfoMode: "comment-aligned", sidebarShowConnectionNotes: true } };+ const defaultSchema = ref(true);+ const schema: TreeNode = { id: "schema", type: "schema", label: "application_schema", schema: "application_schema", connectionId: "conn", comment: "schema comment" };+ const index: TreeNode = { id: "index", type: "elasticsearch-index", label: "logs", searchAliases: ["long_search_alias"], comment: "index comment" };+ const run = execute(`${statement("sidebarTreeLeadingWidthItems")}\n${statement("measureSidebarTreeLeadingWidth")}\n${statement("measureSidebarCommentLabelWidths")}\nreturn measureSidebarCommentLabelWidths;`, {+ computed,+ flatNodes: ref([+ { id: schema.id, depth: 0, node: schema },+ { id: index.id, depth: 1, node: index },+ ]),+ settingsStore,+ store: { getConfig: () => undefined, isDefaultDatabase: () => false, isDefaultSchema: () => defaultSchema.value },+ t: (key: string) => key,+ sidebarCommentLabel: (node: TreeNode) => node.label,+ sidebarTreeSecondaryValue,+ showSidebarRowProductionBadge,+ isSidebarProductionContainer,+ sidebarTreeNodeComment,+ isSidebarCommentAlignableNode,+ alignedSidebarCommentLabelWidths,+ sidebarCommentLabelWidths: widths,+ sidebarCommentMeasureFrame: 0,+ rootRef: ref({}),+ document: { createElement: () => ({ getContext: () => ({ font: "", measureText: (text: string) => ({ width: text.length * 7 }) }) }) },+ window: { getComputedStyle: () => ({ font: "400 14px sans-serif" }) },+ });+ run();+ const fullSchemaWidth = schema.label.length * 7 + "editor.defaultSchema".length * 7 + 24;+ expect(widths.value.get(schema.id)).toBe(fullSchemaWidth);+ expect(widths.value.get(index.id)).toBe(index.label.length * 7 + "long_search_alias".length * 7 + 24);+ defaultSchema.value = false;+ run();+ expect(widths.value.get(schema.id)).toBe(schema.label.length * 7);+ defaultSchema.value = true;+ settingsStore.editorSettings.sidebarAllowHorizontalScroll = false;+ run();+ expect(widths.value.get(schema.id)).toBe(schema.label.length * 7);+ settingsStore.editorSettings.sidebarAllowHorizontalScroll = true;+ run();+ expect(widths.value.get(schema.id)).toBe(fullSchemaWidth);+ });++ function wheelFixture(max = 400) {+ let offset = 0;+ const scroller = {+ clientWidth: 200,+ scrollWidth: max + 200,+ get scrollLeft() {+ return offset;+ },+ set scrollLeft(value: number) {+ offset = Math.max(0, Math.min(max, value));+ },+ };+ const run = (event: WheelEvent) =>+ execute(`${statement("onTreeWheel")}\nonTreeWheel(event);`, {+ event,+ Element,+ currentTreeScroller: () => scroller,+ settingsStore: { editorSettings: { sidebarAllowHorizontalScroll: true } },+ sidebarHorizontalWheelDelta,+ sidebarTreeRowHeight: ref(28),+ scheduleSidebarScrollMetricsUpdate: vi.fn(),+ syncStickyRowHorizontalPosition: vi.fn(),+ });+ return { scroller, run };+ }++ it("consumes Shift wheel only after real scrolling and leaves normal/boundary gestures alone", () => {+ const { scroller, run } = wheelFixture();+ const first = wheel({ shiftKey: true, deltaY: 2, deltaMode: 1, cancelable: true });+ run(first);+ expect(scroller.scrollLeft).toBe(56);+ expect(first.defaultPrevented).toBe(true);+ const normal = wheel({ deltaY: 50, cancelable: true });+ run(normal);+ expect(scroller.scrollLeft).toBe(56);+ expect(normal.defaultPrevented).toBe(false);+ scroller.scrollLeft = 400;+ const boundary = wheel({ shiftKey: true, deltaY: 20, cancelable: true });+ run(boundary);+ expect(boundary.defaultPrevented).toBe(false);+ });++ it("leaves input gestures and non-overflowing trees untouched", () => {+ const { scroller, run } = wheelFixture();+ const event = wheel({ shiftKey: true, deltaY: 50, cancelable: true });+ Object.defineProperty(event, "target", { value: document.createElement("input") });+ run(event);+ expect(scroller.scrollLeft).toBe(0);+ expect(event.defaultPrevented).toBe(false);+ const noOverflow = wheelFixture(0);+ const other = wheel({ shiftKey: true, deltaY: 50, cancelable: true });+ noOverflow.run(other);+ expect(other.defaultPrevented).toBe(false);+ });+});diff --git a/apps/desktop/src/components/sidebar/__tests__/TreeItem.routineComments.spec.ts b/apps/desktop/src/components/sidebar/__tests__/TreeItem.routineComments.spec.tsindex 23e657c947..a2639ddf62 100644--- a/apps/desktop/src/components/sidebar/__tests__/TreeItem.routineComments.spec.ts+++ b/apps/desktop/src/components/sidebar/__tests__/TreeItem.routineComments.spec.ts@@ -152,11 +152,11 @@ describe("TreeItem routine and object comments (#9962)", () => {expect(metadata.contains(label)).toBe(true);expect(metadata.contains(size)).toBe(false);expect(metadata.parentElement).toBe(size.parentElement);- expect(metadata.classList.contains("min-w-0")).toBe(true);- expect(metadata.classList.contains("overflow-hidden")).toBe(true);- expect((label.parentElement as HTMLElement).style.maxWidth).toBe("max(0px, calc(100% - 1rem))");+ expect(metadata.classList.contains(horizontalScroll ? "min-w-max" : "min-w-0")).toBe(true);+ expect(metadata.classList.contains("overflow-hidden")).toBe(!horizontalScroll);+ expect((label.parentElement as HTMLElement).style.maxWidth).toBe(horizontalScroll ? "" : "max(0px, calc(100% - 1rem))");expect(comment.classList.contains("truncate")).toBe(true);- expect(label.classList.contains("truncate")).toBe(true);+ expect(label.classList.contains("truncate")).toBe(horizontalScroll ? false : true);expect(size.classList.contains("shrink-0")).toBe(true);expect(size.classList.contains("ml-auto")).toBe(true);});@@ -185,6 +185,34 @@ describe("TreeItem routine and object comments (#9962)", () => {expect(container.querySelector(".tabular-nums")).toBeNull();});+ it("keeps right-aligned comments visible with a bounded width when the name overflows", async () => {+ commentMode.value = "comment-right";+ allowHorizontalScroll.value = true;+ const frames: FrameRequestCallback[] = [];+ vi.spyOn(window, "requestAnimationFrame").mockImplementation((callback) => {+ frames.push(callback);+ return frames.length;+ });+ const { container } = await mountTreeItem({ ...tableNode, label: "long_table_".repeat(30), comment: "comment ".repeat(200) });+ for (const callback of frames.splice(0)) callback(0);+ await nextTick();+ const comment = container.querySelector<HTMLElement>(".sidebar-object-comment--right")!;+ expect(comment.textContent).toBe("comment ".repeat(200));+ expect(comment.style.maxWidth).toBe("240px");+ expect(container.querySelector(".tree-object-label")!.classList.contains("truncate")).toBe(false);+ });++ it.each(["database", "schema", "column", "index", "trigger"] as const)("allows long %s names to scroll and restores truncation when disabled", async (type) => {+ allowHorizontalScroll.value = true;+ const { container } = await mountTreeItem({ ...tableNode, type, label: "long_name_".repeat(30), meta: { is_primary_key: false, is_nullable: true } as never });+ const label = container.querySelector(".tree-object-label")!;+ expect(label.classList.contains("whitespace-nowrap")).toBe(true);+ expect(label.classList.contains("truncate")).toBe(false);+ allowHorizontalScroll.value = false;+ await nextTick();+ expect(label.classList.contains("truncate")).toBe(true);+ });+it("switches between existing and combined modes without remounting", async () => {const { container } = await mountTreeItem(tableNode);for (const mode of ["comment-and-size", "size", "hidden", "comment-inline", "comment-and-size"]) {diff --git a/apps/desktop/src/lib/__tests__/sidebar/sidebarScrollbar.spec.ts b/apps/desktop/src/lib/__tests__/sidebar/sidebarScrollbar.spec.tsindex 5d1752a6a1..388c1fc960 100644--- a/apps/desktop/src/lib/__tests__/sidebar/sidebarScrollbar.spec.ts+++ b/apps/desktop/src/lib/__tests__/sidebar/sidebarScrollbar.spec.ts@@ -1,5 +1,5 @@import { describe, expect, it } from "vitest";-import { sidebarScrollbarGeometry } from "@/lib/sidebar/sidebarScrollbar";+import { sidebarHorizontalWheelDelta, sidebarScrollbarGeometry } from "@/lib/sidebar/sidebarScrollbar";describe("sidebarScrollbarGeometry", () => {it("returns no thumb when content fits the viewport", () => {@@ -28,4 +28,24 @@ describe("sidebarScrollbarGeometry", () => {maxScrollOffset: 9_800,});});++ it("maps Shift+wheel movement onto horizontal scrolling", () => {+ expect(sidebarHorizontalWheelDelta({ enabled: true, shiftKey: true, deltaX: 0, deltaY: 40, scrollLeft: 10, clientWidth: 100, scrollWidth: 300 })).toBe(40);+ expect(sidebarHorizontalWheelDelta({ enabled: true, shiftKey: true, deltaX: -20, deltaY: 40, scrollLeft: 100, clientWidth: 100, scrollWidth: 300 })).toBe(-20);+ });++ it("normalizes line and page wheel units and clamps the final movement", () => {+ const options = { enabled: true, shiftKey: true, deltaX: 0, deltaY: 2, scrollLeft: 0, clientWidth: 100, scrollWidth: 500 };+ expect(sidebarHorizontalWheelDelta({ ...options, deltaMode: 1, lineHeight: 28 })).toBe(56);+ expect(sidebarHorizontalWheelDelta({ ...options, deltaMode: 2 })).toBe(200);+ expect(sidebarHorizontalWheelDelta({ ...options, scrollLeft: 390, deltaY: 50 })).toBe(10);+ expect(sidebarHorizontalWheelDelta({ ...options, deltaY: -50 })).toBe(0);+ expect(sidebarHorizontalWheelDelta({ ...options, scrollWidth: 100 })).toBe(0);+ });++ it("does not consume disabled or boundary wheel gestures", () => {+ expect(sidebarHorizontalWheelDelta({ enabled: false, shiftKey: true, deltaX: 0, deltaY: 40, scrollLeft: 10, clientWidth: 100, scrollWidth: 300 })).toBe(0);+ expect(sidebarHorizontalWheelDelta({ enabled: true, shiftKey: false, deltaX: 0, deltaY: 40, scrollLeft: 10, clientWidth: 100, scrollWidth: 300 })).toBe(0);+ expect(sidebarHorizontalWheelDelta({ enabled: true, shiftKey: true, deltaX: 0, deltaY: 40, scrollLeft: 200, clientWidth: 100, scrollWidth: 300 })).toBe(0);+ });});diff --git a/apps/desktop/src/lib/__tests__/sidebar/sidebarTreeItemLayout.spec.ts b/apps/desktop/src/lib/__tests__/sidebar/sidebarTreeItemLayout.spec.tsindex 1cc21d584c..339fb2285e 100644--- a/apps/desktop/src/lib/__tests__/sidebar/sidebarTreeItemLayout.spec.ts+++ b/apps/desktop/src/lib/__tests__/sidebar/sidebarTreeItemLayout.spec.ts@@ -15,9 +15,24 @@ import {import type { TreeNode } from "@/types/database";describe("sidebar tree item layout", () => {- it("keeps a table row constrained when it displays a comment", () => {+ it("keeps a table row wide enough when it displays a comment", () => {expect(usesFullWidthTreeLabel("table", true)).toBe(true);- expect(usesFullWidthTreeLabel("table", true, true)).toBe(false);+ expect(usesFullWidthTreeLabel("table", true, true)).toBe(true);+ });++ it("supports ordinary nodes but excludes controls and group headings", () => {+ for (const type of ["database", "schema", "column", "index", "connection", "mongo-db", "elasticsearch-index"] as const) {+ expect(usesFullWidthTreeLabel(type, true, true)).toBe(true);+ expect(usesFullWidthTreeLabel(type, false)).toBe(false);+ }+ for (const type of ["group-tables", "group-columns", "table-search-control", "load-more"] as const) expect(usesFullWidthTreeLabel(type, true)).toBe(false);+ });++ it("includes aligned names, badges, comments and size without letting right comments grow unbounded", () => {+ const row = { depth: 4, label: "id", usesNaturalWidth: true, leadingWidth: 200, comment: "x".repeat(1000), trailingText: "1 KB", trailingWidth: 24 };+ const measure = (text: string) => text.length * 7;+ expect(sidebarTreeNaturalContentWidth([{ ...row, rightAlignedComment: true }], measure)).toBe(64 + 8 + 54 + 200 + 8 + 240 + 8 + 28 + 24);+ expect(sidebarTreeNaturalContentWidth([row], measure)).toBe(64 + 8 + 54 + 200 + 16 + 7000 + 8 + 28 + 24);});it("shows connection notes only after the user opts in", () => {@@ -138,9 +153,9 @@ describe("sidebar tree item layout", () => {expect(isSidebarCommentAlignableNode(func)).toBe(true);expect(usesFullWidthTreeLabel("procedure", true)).toBe(true);- expect(usesFullWidthTreeLabel("procedure", true, true)).toBe(false);+ expect(usesFullWidthTreeLabel("procedure", true, true)).toBe(true);expect(usesFullWidthTreeLabel("function", true)).toBe(true);- expect(usesFullWidthTreeLabel("function", true, true)).toBe(false);+ expect(usesFullWidthTreeLabel("function", true, true)).toBe(true);});it("aligns routine comments among sibling procedures and functions", () => {diff --git a/apps/desktop/src/lib/sidebar/sidebarScrollbar.ts b/apps/desktop/src/lib/sidebar/sidebarScrollbar.tsindex 323c5aab7c..3f04fa4979 100644--- a/apps/desktop/src/lib/sidebar/sidebarScrollbar.ts+++ b/apps/desktop/src/lib/sidebar/sidebarScrollbar.ts@@ -13,6 +13,29 @@ export interface SidebarScrollbarGeometry {maxScrollOffset: number;}+export interface SidebarHorizontalWheelDeltaOptions {+ enabled: boolean;+ shiftKey: boolean;+ deltaX: number;+ deltaY: number;+ deltaMode?: number;+ lineHeight?: number;+ scrollLeft: number;+ clientWidth: number;+ scrollWidth: number;+}++/** Returns the consumable horizontal movement for a Shift+wheel gesture. */+export function sidebarHorizontalWheelDelta({ enabled, shiftKey, deltaX, deltaY, deltaMode = 0, lineHeight = 16, scrollLeft, clientWidth, scrollWidth }: SidebarHorizontalWheelDeltaOptions): number {+ if (!enabled || !shiftKey || scrollWidth <= clientWidth) return 0;+ const unit = deltaMode === 1 ? lineHeight : deltaMode === 2 ? clientWidth : 1;+ const delta = (Math.abs(deltaX) > 0 ? deltaX : deltaY) * unit;+ if (delta === 0) return 0;+ const maxScrollLeft = Math.max(0, scrollWidth - clientWidth);+ const nextScrollLeft = Math.min(maxScrollLeft, Math.max(0, scrollLeft + delta));+ return nextScrollLeft - scrollLeft;+}+export function sidebarScrollbarGeometry({ scrollOffset, viewportSize, contentSize, trackSize, minThumbSize = 24 }: SidebarScrollbarGeometryOptions): SidebarScrollbarGeometry {if (trackSize <= 0 || contentSize <= viewportSize) {return { thumbOffset: 0, thumbSize: 0, maxThumbOffset: 0, maxScrollOffset: 0 };diff --git a/apps/desktop/src/lib/sidebar/sidebarTreeItemLayout.ts b/apps/desktop/src/lib/sidebar/sidebarTreeItemLayout.tsindex e330873b35..098a3c8b32 100644--- a/apps/desktop/src/lib/sidebar/sidebarTreeItemLayout.ts+++ b/apps/desktop/src/lib/sidebar/sidebarTreeItemLayout.ts@@ -44,7 +44,10 @@ const leafTypes: Set<TreeNodeType> = new Set(["datafile",]);-const fullWidthLabelTypes: Set<TreeNodeType> = new Set(["table", "view", "materialized_view", "procedure", "function", "mongo-collection", "mongo-bucket", "dynamodb-table", "vector-collection", "elasticsearch-index"]);+// Search controls are laid out against the viewport. Every other visible tree+// row may contain a user supplied name and must be able to contribute to the+// horizontal scroll width when that setting is enabled.+const nonNaturalWidthTypes: Set<TreeNodeType> = new Set(["table-search-control", "load-more"]);const emptyContainerTypes: Set<TreeNodeType> = new Set(["saved-sql-root", "saved-sql-folder", "type"]);@@ -79,6 +82,7 @@ export function treeItemPaddingLeft(depth: number, indentPx = SIDEBAR_INDENT_DEF}export const trailingCommentGapPx = 8;+export const sidebarRightCommentMaxWidthPx = 240;export const sidebarPinnedActionSlotWidthPx = 24;export function trailingCommentAvailableWidth(containerWidth: number, leadingWidth: number): number {@@ -102,7 +106,11 @@ export interface SidebarTreeNaturalWidthItem {depth: number;label: string;usesNaturalWidth: boolean;+ trailingText?: string;trailingWidth?: number;+ leadingWidth?: number;+ comment?: string;+ rightAlignedComment?: boolean;}// Right padding, expander/icon widths and the two flex gaps before the label.@@ -113,7 +121,10 @@ export function sidebarTreeNaturalContentWidth(items: readonly SidebarTreeNaturafor (const item of items) {if (!item.usesNaturalWidth) continue;const paddingLeft = item.depth * indentPx + 8;- width = Math.max(width, Math.ceil(paddingLeft + sidebarTreeRowChromeWidth + measureText(item.label) + (item.trailingWidth ?? 0)));+ const labelWidth = Math.max(measureText(item.label), item.leadingWidth ?? 0);+ const commentWidth = item.comment ? (item.rightAlignedComment ? trailingCommentGapPx + Math.min(sidebarRightCommentMaxWidthPx, measureText(item.comment)) : 16 + measureText(item.comment)) : 0;+ const trailingWidth = item.trailingText ? trailingCommentGapPx + measureText(item.trailingText) : 0;+ width = Math.max(width, Math.ceil(paddingLeft + sidebarTreeRowChromeWidth + labelWidth + commentWidth + trailingWidth + (item.trailingWidth ?? 0)));}return width;}@@ -159,7 +170,8 @@ export function isSidebarCommentAlignableNode(node: TreeNode): boolean {}export function usesFullWidthTreeLabel(type: TreeNodeType, allowHorizontalScroll: boolean, hasTrailingComment = false): boolean {- return allowHorizontalScroll && !hasTrailingComment && fullWidthLabelTypes.has(type);+ void hasTrailingComment;+ return allowHorizontalScroll && !nonNaturalWidthTypes.has(type) && !type.startsWith("group-") && type !== "type-attributes" && type !== "type-methods";}export function treeLabelWidthClass({ fullWidth, hasTrailingComment, hasInlineAction = false, alignLeading = false }: { fullWidth: boolean; hasTrailingComment: boolean; hasInlineAction?: boolean; alignLeading?: boolean }): string {diff --git a/apps/desktop/src/lib/sidebar/sidebarTreeLabel.ts b/apps/desktop/src/lib/sidebar/sidebarTreeLabel.tsnew file mode 100644index 0000000000..94a502f986--- /dev/null+++ b/apps/desktop/src/lib/sidebar/sidebarTreeLabel.ts@@ -0,0 +1,33 @@+import type { TreeNode, DatabaseType, CustomTypeTreeMemberMeta } from "@/types/database";+import { isTreeGroupNodeType } from "@/lib/sidebar/treeNodeGroup";+import { xuguSchemaDisplayName } from "@/lib/sidebar/xuguPublicSynonyms";+import { elasticsearchIndexAliasLabel } from "@/lib/sidebar/elasticsearchIndexActions";+export type SidebarTreeTranslate = (key: string, values?: Record<string, number>) => string;++export function sidebarTreeDisplayLabel(node: TreeNode, t: SidebarTreeTranslate, databaseType?: DatabaseType): string {+ // Synthetic Xugu scopes are persisted with their reserved protocol value.+ // Resolve them at render time as well, so an already-cached tree never+ // exposes that implementation detail after the feature is introduced.+ if (node.type === "schema" && node.connectionId) {+ if (databaseType === "xugu") return xuguSchemaDisplayName(node.schema ?? node.label);+ }+ if (node.type === "load-more") return t(node.label);+ if (node.type === "object-browser") return t(node.label, { count: node.objectCount ?? 0 });+ // Use the canonical key for persisted trees created before this label was+ // internationalized; those nodes may still contain the old Chinese text.+ if (node.type === "nacos-access-control") return t("nacos.accessControlSidebarLabel");+ if (node.type === "user-admin" || node.type === "xugu-user-admin" || node.type === "dameng-users" || node.type === "dameng-roles" || node.type === "dameng-job-admin" || node.type === "meilisearch-system") return t(node.label);+ if (node.type === "oracle-db-links" || node.type === "linked-server-root") return t(node.label);+ if (node.type === "saved-sql-root") return t(node.label);+ if (node.type === "mqtt-topic" && node.id.endsWith(":mqtt-topic:__console__")) return t(node.label);+ if (node.label === "tree.defaultDatabase") return t(node.label);+ return isTreeGroupNodeType(node.type) ? t(node.label) : node.label;+}++export function sidebarTreeSecondaryValue(node: TreeNode, t: SidebarTreeTranslate): string | undefined {+ if (node.type === "type" && node.customTypeKind) return t(`customType.kinds.${node.customTypeKind}`);+ if (node.type === "type-member") return (node.meta as CustomTypeTreeMemberMeta | undefined)?.displayValue;+ if (node.type === "datafile") return node.xuguDatafilePath;+ if (node.type === "elasticsearch-index") return elasticsearchIndexAliasLabel(node);+ return undefined;+}