fix: restore right sidebar titlebar dragging (#3526)
Co-authored-by: Orca <help@stably.ai>
This commit is contained in:
@@ -4,6 +4,7 @@ import type { RightSidebarTab } from '@/store/slices/editor'
|
||||
import type { CheckStatus } from '../../../../shared/types'
|
||||
import { cn } from '@/lib/utils'
|
||||
import { Tooltip, TooltipContent, TooltipTrigger } from '@/components/ui/tooltip'
|
||||
import { RIGHT_SIDEBAR_HEADER_NO_DRAG_CLASS_NAME } from './right-sidebar-titlebar-drag-regions'
|
||||
import {
|
||||
DropdownMenu,
|
||||
DropdownMenuContent,
|
||||
@@ -51,7 +52,10 @@ export function TopActivityOverflowMenu({
|
||||
<DropdownMenuTrigger asChild>
|
||||
<button
|
||||
type="button"
|
||||
className="relative flex h-[36px] w-8 shrink-0 items-center justify-center text-muted-foreground/60 transition-colors hover:text-muted-foreground focus-visible:outline-none focus-visible:ring-1 focus-visible:ring-ring"
|
||||
className={cn(
|
||||
'relative flex h-[36px] w-8 shrink-0 items-center justify-center text-muted-foreground/60 transition-colors hover:text-muted-foreground focus-visible:outline-none focus-visible:ring-1 focus-visible:ring-ring',
|
||||
RIGHT_SIDEBAR_HEADER_NO_DRAG_CLASS_NAME
|
||||
)}
|
||||
aria-label="More sidebar tabs"
|
||||
>
|
||||
<MoreHorizontal size={16} />
|
||||
@@ -109,7 +113,8 @@ export function ActivityBarButton({
|
||||
<button
|
||||
type="button"
|
||||
className={cn(
|
||||
'relative flex shrink-0 items-center justify-center transition-colors right-sidebar-header-no-drag',
|
||||
'relative flex shrink-0 items-center justify-center transition-colors',
|
||||
RIGHT_SIDEBAR_HEADER_NO_DRAG_CLASS_NAME,
|
||||
isTop ? 'h-[36px] w-9' : 'w-10 h-10',
|
||||
active ? 'text-foreground' : 'text-muted-foreground/60 hover:text-muted-foreground'
|
||||
)}
|
||||
|
||||
@@ -29,6 +29,11 @@ import {
|
||||
import { getActiveChecksStatus } from './active-checks-status'
|
||||
import { getVisibleRightSidebarActivityItems } from './right-sidebar-activity-visibility'
|
||||
import { useShortcutLabel } from '@/hooks/useShortcutLabel'
|
||||
import {
|
||||
RIGHT_SIDEBAR_HEADER_NO_DRAG_CLASS_NAME,
|
||||
RIGHT_SIDEBAR_TOP_ACTIVITY_STRIP_CLASS_NAME,
|
||||
RIGHT_SIDEBAR_WINDOWS_TOP_ACTIVITY_STRIP_CLASS_NAME
|
||||
} from './right-sidebar-titlebar-drag-regions'
|
||||
|
||||
const MIN_WIDTH = 220
|
||||
// Why: long file names (e.g. construction drawing sheets, multi-part document
|
||||
@@ -220,41 +225,58 @@ function RightSidebarInner(): React.JSX.Element {
|
||||
<ContextMenuTrigger asChild>
|
||||
<div
|
||||
ref={topActivityStripRef}
|
||||
className="right-sidebar-activity-strip flex min-w-0 flex-1 items-center overflow-hidden pl-2 right-sidebar-header-no-drag"
|
||||
className={RIGHT_SIDEBAR_TOP_ACTIVITY_STRIP_CLASS_NAME}
|
||||
>
|
||||
{/* Why: the top strip shares a narrow titlebar with the close
|
||||
button and Windows controls. Overflow goes behind More
|
||||
instead of creating a horizontally scrollable toolbar. */}
|
||||
<div className="flex min-w-0 shrink">
|
||||
{topActivityLayout.visibleItems.map((item) => (
|
||||
<ActivityBarButton
|
||||
key={item.id}
|
||||
item={item}
|
||||
active={effectiveTab === item.id}
|
||||
onClick={() => setRightSidebarTab(item.id)}
|
||||
layout="top"
|
||||
statusIndicator={item.id === 'checks' ? checksStatus : null}
|
||||
<div
|
||||
className={cn(
|
||||
'flex min-w-0 shrink',
|
||||
RIGHT_SIDEBAR_HEADER_NO_DRAG_CLASS_NAME
|
||||
)}
|
||||
>
|
||||
{/* Why: the top strip shares a narrow titlebar with the close
|
||||
button and Windows controls. Overflow goes behind More
|
||||
instead of creating a horizontally scrollable toolbar. */}
|
||||
<div className="flex min-w-0 shrink">
|
||||
{topActivityLayout.visibleItems.map((item) => (
|
||||
<ActivityBarButton
|
||||
key={item.id}
|
||||
item={item}
|
||||
active={effectiveTab === item.id}
|
||||
onClick={() => setRightSidebarTab(item.id)}
|
||||
layout="top"
|
||||
statusIndicator={item.id === 'checks' ? checksStatus : null}
|
||||
/>
|
||||
))}
|
||||
</div>
|
||||
{topActivityLayout.overflowItems.length > 0 && (
|
||||
<TopActivityOverflowMenu
|
||||
items={topActivityLayout.overflowItems}
|
||||
activeTab={effectiveTab}
|
||||
onSelect={setRightSidebarTab}
|
||||
checksStatus={checksStatus}
|
||||
/>
|
||||
))}
|
||||
)}
|
||||
</div>
|
||||
{topActivityLayout.overflowItems.length > 0 && (
|
||||
<TopActivityOverflowMenu
|
||||
items={topActivityLayout.overflowItems}
|
||||
activeTab={effectiveTab}
|
||||
onSelect={setRightSidebarTab}
|
||||
checksStatus={checksStatus}
|
||||
/>
|
||||
)}
|
||||
</div>
|
||||
</ContextMenuTrigger>
|
||||
<div className="flex shrink-0 items-center pr-1 right-sidebar-header-no-drag">
|
||||
<div
|
||||
className={cn(
|
||||
'flex shrink-0 items-center pr-1',
|
||||
RIGHT_SIDEBAR_HEADER_NO_DRAG_CLASS_NAME
|
||||
)}
|
||||
>
|
||||
{closeButton}
|
||||
</div>
|
||||
</TooltipProvider>
|
||||
)}
|
||||
{isWindows && (
|
||||
<TooltipProvider delayDuration={400}>
|
||||
<div className="ml-auto flex shrink-0 items-center pr-1 right-sidebar-header-no-drag">
|
||||
<div
|
||||
className={cn(
|
||||
'ml-auto flex shrink-0 items-center pr-1',
|
||||
RIGHT_SIDEBAR_HEADER_NO_DRAG_CLASS_NAME
|
||||
)}
|
||||
>
|
||||
{closeButton}
|
||||
</div>
|
||||
</TooltipProvider>
|
||||
@@ -265,7 +287,7 @@ function RightSidebarInner(): React.JSX.Element {
|
||||
<ContextMenuTrigger asChild>
|
||||
<div
|
||||
ref={topActivityStripRef}
|
||||
className="right-sidebar-activity-strip flex h-10 min-h-10 items-center border-b border-border px-2 right-sidebar-header-no-drag"
|
||||
className={RIGHT_SIDEBAR_WINDOWS_TOP_ACTIVITY_STRIP_CLASS_NAME}
|
||||
>
|
||||
{/* Why: Windows has fixed native-style controls in the titlebar
|
||||
area; keep sidebar navigation in the sidebar body so the
|
||||
|
||||
+191
@@ -0,0 +1,191 @@
|
||||
import { cloneElement, isValidElement, type ReactElement, type ReactNode } from 'react'
|
||||
import { renderToStaticMarkup } from 'react-dom/server'
|
||||
import { beforeEach, describe, expect, it, vi } from 'vitest'
|
||||
import RightSidebar from './index'
|
||||
import { TopActivityOverflowMenu } from './activity-bar-buttons'
|
||||
import { RIGHT_SIDEBAR_HEADER_NO_DRAG_CLASS_NAME } from './right-sidebar-titlebar-drag-regions'
|
||||
|
||||
const mockAppState = vi.hoisted(() => ({
|
||||
activityBarPosition: 'top' as 'top' | 'side'
|
||||
}))
|
||||
|
||||
vi.mock('@/hooks/useSidebarResize', () => ({
|
||||
useSidebarResize: () => ({
|
||||
containerRef: { current: null },
|
||||
isResizing: false,
|
||||
onResizeStart: vi.fn()
|
||||
})
|
||||
}))
|
||||
|
||||
vi.mock('@/hooks/useShortcutLabel', () => ({
|
||||
useShortcutLabel: (actionId: string) => actionId
|
||||
}))
|
||||
|
||||
vi.mock('@/store', () => ({
|
||||
useAppStore: (selector: (state: Record<string, unknown>) => unknown) =>
|
||||
selector({
|
||||
rightSidebarOpen: true,
|
||||
rightSidebarWidth: 350,
|
||||
setRightSidebarWidth: vi.fn(),
|
||||
rightSidebarTab: 'explorer',
|
||||
setRightSidebarTab: vi.fn(),
|
||||
toggleRightSidebar: vi.fn(),
|
||||
activityBarPosition: mockAppState.activityBarPosition,
|
||||
setActivityBarPosition: vi.fn(),
|
||||
checksByWorktreeId: {},
|
||||
keybindings: {}
|
||||
})
|
||||
}))
|
||||
|
||||
vi.mock('@/store/selectors', () => ({
|
||||
useActiveWorktree: () => ({ id: 'worktree-1', repoId: 'repo-1' }),
|
||||
useRepoById: () => ({ id: 'repo-1', kind: 'git', connectionId: null })
|
||||
}))
|
||||
|
||||
vi.mock('@/components/ui/tooltip', () => ({
|
||||
TooltipProvider: ({ children }: { children: ReactNode }) => <>{children}</>,
|
||||
Tooltip: ({ children }: { children: ReactNode }) => <>{children}</>,
|
||||
TooltipContent: ({ children }: { children: ReactNode }) => <span>{children}</span>,
|
||||
TooltipTrigger: ({ children, asChild }: { children: ReactNode; asChild?: boolean }) => {
|
||||
if (asChild && isValidElement(children)) {
|
||||
return cloneElement(children as ReactElement<Record<string, unknown>>, {
|
||||
'data-tooltip-trigger': 'true'
|
||||
})
|
||||
}
|
||||
return <span data-tooltip-trigger>{children}</span>
|
||||
}
|
||||
}))
|
||||
|
||||
vi.mock('@/components/ui/context-menu', () => ({
|
||||
ContextMenu: ({ children }: { children: ReactNode }) => <>{children}</>,
|
||||
ContextMenuTrigger: ({ children, asChild }: { children: ReactNode; asChild?: boolean }) => {
|
||||
if (asChild && isValidElement(children)) {
|
||||
return cloneElement(children as ReactElement<Record<string, unknown>>, {
|
||||
'data-context-menu-trigger': 'true'
|
||||
})
|
||||
}
|
||||
return <span data-context-menu-trigger>{children}</span>
|
||||
},
|
||||
ContextMenuContent: ({ children }: { children: ReactNode }) => <>{children}</>,
|
||||
ContextMenuLabel: ({ children }: { children: ReactNode }) => <>{children}</>,
|
||||
ContextMenuRadioGroup: ({ children }: { children: ReactNode }) => <>{children}</>,
|
||||
ContextMenuRadioItem: ({ children }: { children: ReactNode }) => <>{children}</>
|
||||
}))
|
||||
|
||||
vi.mock('@/components/ui/dropdown-menu', () => ({
|
||||
DropdownMenu: ({ children }: { children: ReactNode }) => <>{children}</>,
|
||||
DropdownMenuContent: ({ children }: { children: ReactNode }) => <>{children}</>,
|
||||
DropdownMenuItem: ({ children }: { children: ReactNode }) => <>{children}</>,
|
||||
DropdownMenuShortcut: ({ children }: { children: ReactNode }) => <>{children}</>,
|
||||
DropdownMenuTrigger: ({ children, asChild }: { children: ReactNode; asChild?: boolean }) => {
|
||||
if (asChild && isValidElement(children)) {
|
||||
return cloneElement(children as ReactElement<Record<string, unknown>>, {
|
||||
'data-dropdown-trigger': 'true'
|
||||
})
|
||||
}
|
||||
return <span data-dropdown-trigger>{children}</span>
|
||||
}
|
||||
}))
|
||||
|
||||
vi.mock('./FileExplorer', () => ({
|
||||
default: () => <div data-file-explorer />
|
||||
}))
|
||||
|
||||
vi.mock('./SourceControl', () => ({
|
||||
default: () => <div data-source-control />
|
||||
}))
|
||||
|
||||
vi.mock('./Search', () => ({
|
||||
default: () => <div data-search-panel />
|
||||
}))
|
||||
|
||||
vi.mock('./ChecksPanel', () => ({
|
||||
default: () => <div data-checks-panel />
|
||||
}))
|
||||
|
||||
vi.mock('./PortsPanel', () => ({
|
||||
default: () => <div data-ports-panel />
|
||||
}))
|
||||
|
||||
function openingTag(markup: string, className: string): string {
|
||||
const match = markup.match(new RegExp(`<[^>]+class="[^"]*${className}[^"]*"[^>]*>`))
|
||||
if (!match) {
|
||||
throw new Error(`opening tag with class "${className}" not found in ${markup}`)
|
||||
}
|
||||
return match[0]
|
||||
}
|
||||
|
||||
function buttonOpeningTag(markup: string, ariaLabelPrefix: string): string {
|
||||
const escapedPrefix = ariaLabelPrefix.replace(/[.*+?^${}()|[\]\\]/g, '\\$&')
|
||||
const match = markup.match(new RegExp(`<button[^>]+aria-label="${escapedPrefix}[^"]*"[^>]*>`))
|
||||
if (!match) {
|
||||
throw new Error(`button with aria-label prefix "${ariaLabelPrefix}" not found in ${markup}`)
|
||||
}
|
||||
return match[0]
|
||||
}
|
||||
|
||||
function expectNoDrag(tag: string): void {
|
||||
expect(tag).toContain(RIGHT_SIDEBAR_HEADER_NO_DRAG_CLASS_NAME)
|
||||
}
|
||||
|
||||
describe('rendered right sidebar titlebar drag regions', () => {
|
||||
beforeEach(() => {
|
||||
mockAppState.activityBarPosition = 'top'
|
||||
})
|
||||
|
||||
it('keeps the rendered top activity strip draggable, context-menuable, and only controls no-drag', () => {
|
||||
const markup = renderToStaticMarkup(<RightSidebar />)
|
||||
const header = openingTag(markup, 'right-sidebar-header-drag')
|
||||
const activityStrip = openingTag(markup, 'right-sidebar-activity-strip')
|
||||
|
||||
expect(header).not.toContain(RIGHT_SIDEBAR_HEADER_NO_DRAG_CLASS_NAME)
|
||||
expect(activityStrip).not.toContain(RIGHT_SIDEBAR_HEADER_NO_DRAG_CLASS_NAME)
|
||||
expect(activityStrip).toContain('data-context-menu-trigger="true"')
|
||||
expect(markup).toContain('right-sidebar-header-drag')
|
||||
|
||||
expectNoDrag(buttonOpeningTag(markup, 'Explorer'))
|
||||
expectNoDrag(buttonOpeningTag(markup, 'Search'))
|
||||
expectNoDrag(buttonOpeningTag(markup, 'Source Control'))
|
||||
expectNoDrag(buttonOpeningTag(markup, 'Checks'))
|
||||
expect(buttonOpeningTag(markup, 'Toggle right sidebar')).toContain('sidebar-toggle')
|
||||
expect(markup).toContain(RIGHT_SIDEBAR_HEADER_NO_DRAG_CLASS_NAME)
|
||||
})
|
||||
|
||||
it('keeps the overflow trigger no-drag when it renders', () => {
|
||||
const markup = renderToStaticMarkup(
|
||||
<TopActivityOverflowMenu
|
||||
items={[
|
||||
{
|
||||
id: 'checks',
|
||||
icon: () => <span data-checks-icon />,
|
||||
title: 'Checks',
|
||||
shortcut: 'shortcut'
|
||||
}
|
||||
]}
|
||||
activeTab="explorer"
|
||||
onSelect={vi.fn()}
|
||||
/>
|
||||
)
|
||||
|
||||
const overflowButton = openingTag(markup, RIGHT_SIDEBAR_HEADER_NO_DRAG_CLASS_NAME)
|
||||
expect(overflowButton).toContain('aria-label="More sidebar tabs"')
|
||||
})
|
||||
|
||||
it('keeps side activity-bar controls no-drag without cancelling the side header drag region', () => {
|
||||
mockAppState.activityBarPosition = 'side'
|
||||
|
||||
const markup = renderToStaticMarkup(<RightSidebar />)
|
||||
const sideHeader = openingTag(markup, 'right-sidebar-header-drag')
|
||||
const sideStrip = openingTag(markup, 'side-activity-bar-windows-inset')
|
||||
|
||||
expect(sideHeader).not.toContain(RIGHT_SIDEBAR_HEADER_NO_DRAG_CLASS_NAME)
|
||||
expect(sideHeader).toContain('right-sidebar-header-side-inset')
|
||||
expect(sideStrip).toContain('data-context-menu-trigger="true"')
|
||||
|
||||
expectNoDrag(buttonOpeningTag(markup, 'Explorer'))
|
||||
expectNoDrag(buttonOpeningTag(markup, 'Search'))
|
||||
expectNoDrag(buttonOpeningTag(markup, 'Source Control'))
|
||||
expectNoDrag(buttonOpeningTag(markup, 'Checks'))
|
||||
expect(buttonOpeningTag(markup, 'Toggle right sidebar')).toContain('sidebar-toggle')
|
||||
})
|
||||
})
|
||||
@@ -0,0 +1,21 @@
|
||||
import { describe, expect, it } from 'vitest'
|
||||
import {
|
||||
RIGHT_SIDEBAR_HEADER_NO_DRAG_CLASS_NAME,
|
||||
RIGHT_SIDEBAR_TOP_ACTIVITY_STRIP_CLASS_NAME,
|
||||
RIGHT_SIDEBAR_WINDOWS_TOP_ACTIVITY_STRIP_CLASS_NAME
|
||||
} from './right-sidebar-titlebar-drag-regions'
|
||||
|
||||
describe('right sidebar titlebar drag regions', () => {
|
||||
it('keeps the top activity strips from cancelling header window drag', () => {
|
||||
expect(RIGHT_SIDEBAR_TOP_ACTIVITY_STRIP_CLASS_NAME).not.toContain(
|
||||
RIGHT_SIDEBAR_HEADER_NO_DRAG_CLASS_NAME
|
||||
)
|
||||
expect(RIGHT_SIDEBAR_WINDOWS_TOP_ACTIVITY_STRIP_CLASS_NAME).not.toContain(
|
||||
RIGHT_SIDEBAR_HEADER_NO_DRAG_CLASS_NAME
|
||||
)
|
||||
})
|
||||
|
||||
it('keeps a shared no-drag class for interactive header controls', () => {
|
||||
expect(RIGHT_SIDEBAR_HEADER_NO_DRAG_CLASS_NAME).toBe('right-sidebar-header-no-drag')
|
||||
})
|
||||
})
|
||||
@@ -0,0 +1,9 @@
|
||||
// Why: Electron drag hit-testing is class-based and ignores z-index. Keep the
|
||||
// stretchy activity strip draggable while opting only real controls out.
|
||||
export const RIGHT_SIDEBAR_HEADER_NO_DRAG_CLASS_NAME = 'right-sidebar-header-no-drag'
|
||||
|
||||
export const RIGHT_SIDEBAR_TOP_ACTIVITY_STRIP_CLASS_NAME =
|
||||
'right-sidebar-activity-strip flex min-w-0 flex-1 items-center overflow-hidden pl-2'
|
||||
|
||||
export const RIGHT_SIDEBAR_WINDOWS_TOP_ACTIVITY_STRIP_CLASS_NAME =
|
||||
'right-sidebar-activity-strip flex h-10 min-h-10 items-center border-b border-border px-2'
|
||||
@@ -191,6 +191,7 @@ function setLineageFixtureState(groupBy: 'none' | 'repo' = 'none'): void {
|
||||
activeModal: '',
|
||||
activeView: 'terminal',
|
||||
activeWorktreeId: null,
|
||||
agentStatusEpoch: 0,
|
||||
agentStatusByPaneKey: {},
|
||||
browserTabsByWorktree: {},
|
||||
clearPendingRevealWorktreeId: vi.fn(),
|
||||
@@ -207,6 +208,7 @@ function setLineageFixtureState(groupBy: 'none' | 'repo' = 'none'): void {
|
||||
ptyIdsByTabId: {},
|
||||
reorderRepos: vi.fn(),
|
||||
reportVisibleGitHubPRRefreshCandidates: vi.fn(),
|
||||
retainedAgentsByPaneKey: {},
|
||||
repos: [repo],
|
||||
runtimePaneTitlesByTabId: {},
|
||||
setFilterRepoIds: vi.fn(),
|
||||
@@ -259,6 +261,7 @@ function setProjectGroupWithoutWorktreeRowsState(filterRepoIds: string[] = []):
|
||||
activeModal: '',
|
||||
activeView: 'terminal',
|
||||
activeWorktreeId: null,
|
||||
agentStatusEpoch: 0,
|
||||
agentStatusByPaneKey: {},
|
||||
browserTabsByWorktree: {},
|
||||
clearPendingRevealWorktreeId: vi.fn(),
|
||||
@@ -276,6 +279,7 @@ function setProjectGroupWithoutWorktreeRowsState(filterRepoIds: string[] = []):
|
||||
ptyIdsByTabId: {},
|
||||
reorderRepos: vi.fn(),
|
||||
reportVisibleGitHubPRRefreshCandidates: vi.fn(),
|
||||
retainedAgentsByPaneKey: {},
|
||||
repos: [repo],
|
||||
runtimePaneTitlesByTabId: {},
|
||||
setFilterRepoIds: vi.fn(),
|
||||
|
||||
Reference in New Issue
Block a user