fix(sidebar): stop sticky headers at connection boundaries
Closes #9996
This commit is contained in:
5 files changed
+46
-48
No files matched your search
@@ -844,16 +844,6 @@ function readExpandedSidebarSchemas(): Array<{ id: string; label: string }> {
|
||||
return expanded;
|
||||
}
|
||||
|
||||
// The plain (non-virtualized) renderer uses the same container selection as the
|
||||
// virtual sticky overlay: database containers take precedence, while schema
|
||||
// containers stick only in trees without a database-level container.
|
||||
function isPlainStickyContainerNode(index: number): boolean {
|
||||
// Mirror the virtual branch's sticky overlay: both suppress sticky headers
|
||||
// while a search filter is active so filtered rows don't pin at the top.
|
||||
if (isTreeSearchFiltering.value) return false;
|
||||
return flatTreeIndex.value.stickyContainerIndexByIndex[index] === index;
|
||||
}
|
||||
|
||||
const sidebarLayoutMonitor = createSidebarLayoutMonitor({
|
||||
readContext: () => ({
|
||||
flatNodeCount: flatNodes.value.length,
|
||||
@@ -1058,10 +1048,9 @@ watch(
|
||||
);
|
||||
|
||||
// --- Sticky database header ---
|
||||
// RecycleScroller positions each row absolutely, so CSS `position: sticky` on
|
||||
// a database row can't work. Instead we overlay a pinned row from this parent
|
||||
// component, tracking scroll offset to find the topmost visible database-level
|
||||
// ancestor. The overlay reuses <TreeItem>, so collapse/expand comes for free.
|
||||
// Both renderers use the same overlay instead of CSS `position: sticky` on
|
||||
// individual rows. A shared overlay can be pushed out by the next connection
|
||||
// boundary, while native sticky rows would cover that non-sticky connection.
|
||||
const stickyScrollTop = ref(0);
|
||||
const sidebarScrollMetrics = ref({ scrollTop: 0, scrollLeft: 0, clientHeight: 0, clientWidth: 0, scrollHeight: 0, scrollWidth: 0 });
|
||||
const isScrollingSidebar = ref(false);
|
||||
@@ -1080,7 +1069,7 @@ function updateSidebarScrollMetrics() {
|
||||
return;
|
||||
}
|
||||
|
||||
if (useVirtualTree.value) stickyScrollTop.value = scroller.scrollTop;
|
||||
stickyScrollTop.value = scroller.scrollTop;
|
||||
sidebarScrollMetrics.value = {
|
||||
scrollTop: scroller.scrollTop,
|
||||
scrollLeft: scroller.scrollLeft,
|
||||
@@ -1141,28 +1130,30 @@ watch(
|
||||
{ flush: "post" },
|
||||
);
|
||||
|
||||
const stickyNode = computed<FlatTreeNode | null>(() => {
|
||||
if (!useVirtualTree.value || isTreeSearchFiltering.value) return null;
|
||||
const stickyContainerIndex = computed(() => {
|
||||
if (isTreeSearchFiltering.value) return -1;
|
||||
const nodes = flatNodes.value;
|
||||
const len = nodes.length;
|
||||
if (len === 0) return null;
|
||||
if (len === 0) return -1;
|
||||
|
||||
const topIndex = Math.min(Math.floor(stickyScrollTop.value / SIDEBAR_TREE_ROW_HEIGHT), len - 1);
|
||||
const containerIndex = flatTreeIndex.value.stickyContainerIndexByIndex[topIndex] ?? -1;
|
||||
if (containerIndex < 0) return null;
|
||||
return stickyScrollTop.value > containerIndex * SIDEBAR_TREE_ROW_HEIGHT ? nodes[containerIndex] : null;
|
||||
if (containerIndex < 0) return -1;
|
||||
return stickyScrollTop.value > containerIndex * SIDEBAR_TREE_ROW_HEIGHT ? containerIndex : -1;
|
||||
});
|
||||
|
||||
const stickyNode = computed<FlatTreeNode | null>(() => flatNodes.value[stickyContainerIndex.value] ?? null);
|
||||
|
||||
const stickyHeaderStyle = computed<CSSProperties>(() => {
|
||||
const node = stickyNode.value;
|
||||
if (!node) return {};
|
||||
const currentIndex = flatTreeIndex.value.flatNodeIndexById.get(node.id) ?? -1;
|
||||
const currentIndex = stickyContainerIndex.value;
|
||||
if (currentIndex < 0) return {};
|
||||
// The next peer index is precomputed with the flat-tree snapshot so scrolling
|
||||
// never scans the remaining tree. Connection boundaries reset the lookup.
|
||||
const nextDatabaseIndex = SCHEMA_LEVEL_TYPES.has(node.type) ? flatTreeIndex.value.nextSchemaContainerIndexByIndex[currentIndex] : flatTreeIndex.value.nextDatabaseContainerIndexByIndex[currentIndex];
|
||||
if (nextDatabaseIndex < 0) return {};
|
||||
const distanceToNext = nextDatabaseIndex * SIDEBAR_TREE_ROW_HEIGHT - stickyScrollTop.value;
|
||||
const node = flatNodes.value[currentIndex];
|
||||
if (!node) return {};
|
||||
const nextContainerIndex = SCHEMA_LEVEL_TYPES.has(node.type) ? flatTreeIndex.value.nextSchemaContainerIndexByIndex[currentIndex] : flatTreeIndex.value.nextDatabaseContainerIndexByIndex[currentIndex];
|
||||
const nextBoundaryIndex = flatTreeIndex.value.nextBoundaryIndexByIndex[currentIndex] ?? -1;
|
||||
const nextCollisionIndex = nextContainerIndex < 0 ? nextBoundaryIndex : nextBoundaryIndex < 0 ? nextContainerIndex : Math.min(nextContainerIndex, nextBoundaryIndex);
|
||||
if (nextCollisionIndex < 0) return {};
|
||||
const distanceToNext = nextCollisionIndex * SIDEBAR_TREE_ROW_HEIGHT - stickyScrollTop.value;
|
||||
if (distanceToNext >= SIDEBAR_TREE_ROW_HEIGHT) return {};
|
||||
return {
|
||||
transform: `translateY(${Math.min(0, distanceToNext - SIDEBAR_TREE_ROW_HEIGHT)}px)`,
|
||||
@@ -1495,7 +1486,7 @@ async function flashSidebarNode(nodeId: string) {
|
||||
|
||||
function topOcclusionHeightForSidebarNode(nodeId: string): number {
|
||||
const sticky = stickyNode.value;
|
||||
if (!useVirtualTree.value || !sticky || sticky.id === nodeId) return 0;
|
||||
if (!sticky || sticky.id === nodeId) return 0;
|
||||
return SIDEBAR_TREE_ROW_HEIGHT;
|
||||
}
|
||||
|
||||
@@ -2712,7 +2703,7 @@ defineExpose({ focusSearch, createNewGroup, collapseAllTreeNodes, locateTabInSid
|
||||
<div ref="plainTreeScrollerRef" class="sidebar-tree connection-tree-scroller h-full overflow-y-auto" :class="sidebarTreeOverflowClass" :style="sidebarTreeScrollerStyle" @click="clearSidebarSelection" @scroll.passive="onTreeScroll">
|
||||
<div class="connection-tree-content">
|
||||
<TreeItem
|
||||
v-for="(item, index) in flatNodes"
|
||||
v-for="item in flatNodes"
|
||||
:key="item.renderKey"
|
||||
:node="item.node"
|
||||
:depth="item.depth"
|
||||
@@ -2721,13 +2712,22 @@ defineExpose({ focusSearch, createNewGroup, collapseAllTreeNodes, locateTabInSid
|
||||
:pending-rename="pendingRenameNodeId === item.node.id"
|
||||
:highlighted="highlightedNodeId === item.id"
|
||||
:comment-label-width="sidebarCommentLabelWidths.get(item.node.id)"
|
||||
:sticky-header="isPlainStickyContainerNode(index)"
|
||||
@context-menu="(event, node) => openSidebarContextMenu(event, node, contextMenuSlot.onContextMenu)"
|
||||
@rename-started="pendingRenameNodeId = null"
|
||||
@group-created="startRenamingCreatedGroup"
|
||||
/>
|
||||
</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)"
|
||||
@context-menu="(event, node) => openSidebarContextMenu(event, node, contextMenuSlot.onContextMenu)"
|
||||
/>
|
||||
</div>
|
||||
<div
|
||||
v-if="hasSidebarVerticalOverflow"
|
||||
ref="sidebarScrollbarTrackRef"
|
||||
|
||||
@@ -202,10 +202,6 @@ const props = defineProps<{
|
||||
pendingRename?: boolean;
|
||||
highlighted?: boolean;
|
||||
commentLabelWidth?: number;
|
||||
/** Plain (non-virtualized) renderer: make database/schema container rows
|
||||
* stick to the top of the tree scroller while their children scroll under
|
||||
* them (mirrors the overlay sticky header of the virtual renderer). */
|
||||
stickyHeader?: boolean;
|
||||
}>();
|
||||
|
||||
const emit = defineEmits<{
|
||||
@@ -1610,7 +1606,7 @@ function onKeydown(event: KeyboardEvent) {
|
||||
</LightTooltip>
|
||||
</div>
|
||||
|
||||
<div v-else :class="{ 'sidebar-tree-item--sticky': stickyHeader }" @contextmenu="onTreeItemContextMenu">
|
||||
<div v-else @contextmenu="onTreeItemContextMenu">
|
||||
<LightTooltip :text="visibleLabel(node)" :disabled="isTooltipDisabled()" side="right" :side-offset="8" :delay="0" :close-delay="30" :surface="detailTooltip ? 'popover' : 'foreground'">
|
||||
<div
|
||||
ref="rowRef"
|
||||
@@ -1934,18 +1930,6 @@ function onKeydown(event: KeyboardEvent) {
|
||||
background-color: transparent !important;
|
||||
}
|
||||
|
||||
/* Plain (non-virtualized) renderer: database/schema container rows stick to
|
||||
the top of the tree scroller while their children scroll under them,
|
||||
mirroring the overlay sticky header the virtual renderer uses. The row is
|
||||
min-h-7, so a solid background guarantees no content shows through while
|
||||
rows slide underneath. */
|
||||
.sidebar-tree-item--sticky {
|
||||
position: sticky;
|
||||
top: 0;
|
||||
z-index: 2;
|
||||
background-color: var(--sidebar);
|
||||
}
|
||||
|
||||
.tree-item-connection-tint:hover::before {
|
||||
background-color: var(--tree-connection-row-hover-bg, var(--tree-connection-row-bg));
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user