diff --git a/src/client/changes/GitLens.tsx b/src/client/changes/GitLens.tsx index 522dc60a..0b134860 100644 --- a/src/client/changes/GitLens.tsx +++ b/src/client/changes/GitLens.tsx @@ -27,7 +27,7 @@ import type { SidebarDiffRef } from '../state.ts' import { buildRepositoryLabels } from './repo-labels.ts' import { RepoSwitcher } from './RepoSwitcher.tsx' import { - ActionButton, ConfirmDialog, IconButton, Menu, Notice, StatusBadge, TextArea, WorkbenchSection, invalidateGitStatus, statusOfXY, + ActionButton, ConfirmDialog, IconButton, Menu, Notice, StatusBadge, TextArea, WorkbenchSection, WorkbenchStack, invalidateGitStatus, statusOfXY, useGitStatus, type GitFileStatus, type GitTone, type StatusTone, } from '../ui/index.ts' import { buildChangeTree, sumLineCounts, type ChangeDir, type ChangeFile, type ChangeNode } from './change-tree.ts' @@ -432,6 +432,8 @@ export function GitLens(props: GitLensProps) { const [graphRefresh, setGraphRefresh] = useState(0) const [changesOpen, setChangesOpen] = useState(true) const [graphOpen, setGraphOpen] = useState(true) + /** Section weights of the changes/graph stack; kept in memory, the Git page has no settings key yet. */ + const [sectionWeights, setSectionWeights] = useState>({}) /** * The open More Actions menu: the trigger's viewport corner (null = closed). * Its repo/worktree rows carry nested submenus, which the primitives anchor @@ -1152,8 +1154,18 @@ export function GitLens(props: GitLensProps) { )} {isRepo && ( + - } label={t('commit')} disabled={!canCommit} onClick={commit} /> @@ -1221,9 +1233,15 @@ export function GitLens(props: GitLensProps) { } - )} - - {isRepo &&
+ ), + }, + { + id: 'graph', + title: t('gitGraph'), + open: graphOpen, + weight: 1, + content: ( +
{graphOpen &&
@@ -1240,7 +1258,12 @@ export function GitLens(props: GitLensProps) { />
}
-
} +
+ ), + }, + ]} + /> + )} {/* A sibling of the scroller: usable even with both sections folded. */} diff --git a/src/client/changes/changes.module.css b/src/client/changes/changes.module.css index 31b6aab6..0b7f2171 100644 --- a/src/client/changes/changes.module.css +++ b/src/client/changes/changes.module.css @@ -79,10 +79,12 @@ flex-direction: column; } -.changesSection { flex: none; } -/* Bound the section's minimum, not its maximum: 28px header + 220px viewport. - An automatic minimum would let the entire history stretch the outer scroller. */ -.graphSection { flex: 1; min-height: 248px; display: flex; flex-direction: column; } +.changesSection { display: flex; flex: 1; flex-direction: column; min-height: 0; min-width: 0; overflow: hidden; } +/* The stack hands each open pane a flex height; the section's own body scrolls, + so both sections keep their header while the list moves under it. */ +.changesBody { display: flex; flex: 1; flex-direction: column; min-height: 0; overflow: hidden; } +.changesSection [data-scm-changes] { flex: 1; min-height: 0; overflow-y: auto; } +.graphSection { display: flex; flex: 1; flex-direction: column; min-height: 248px; overflow: hidden; } .graphArea { flex: 1; display: flex; flex-direction: column; min-height: 0; } .scmHeader { display: flex; align-items: center; min-height: 28px; padding: 0 6px; } diff --git a/src/client/clues/tab/CluesTab.tsx b/src/client/clues/tab/CluesTab.tsx index 880dd15c..7f5c9a22 100644 --- a/src/client/clues/tab/CluesTab.tsx +++ b/src/client/clues/tab/CluesTab.tsx @@ -31,7 +31,7 @@ import { t } from '../../locales.ts' import { CluePacksSection } from './packs.tsx' import { ClueBrowser } from './browser.tsx' import { ClueHelpOverlay, clueHelpSeen, markClueHelpSeen } from './help.tsx' -import { ActionButton, EmptyState, IconButton, SidebarToolbar, WorkbenchSection } from '../../ui/index.ts' +import { ActionButton, EmptyState, IconButton, SidebarToolbar, WorkbenchSection, WorkbenchStack } from '../../ui/index.ts' import { openClueDetailWindow, type ClueDetailTarget } from '../windows/detail.tsx' import { openClueCollectionForTarget } from '../windows/collect.tsx' import { openPackManagementWindow } from '../windows/pack.tsx' @@ -41,7 +41,6 @@ import { LoadingIndicator } from '../../ui/LoadingIndicator.tsx' import { SelectMenu } from '../../ui/SelectMenu.tsx' import design from '../../ui/design.module.css' import css from './clues-tab.module.css' -import { SectionStack } from './SectionStack.tsx' /** The plugin-settings key of the clue tab (one sparse blob). */ const CLUE_TAB_SETTINGS_KEY = 'clues' @@ -378,7 +377,7 @@ export function CluesTab({ ctx, store, scope, visible }: CluesTabProps): ReactNo )} {ready && browseWorkspaceId !== undefined && ( - div > div:first-child { border-top: 0; } -.sash:hover, .sash:focus-visible, .sash:active { - background-color: var(--ds-sidebar-accent); -} -@media (pointer: coarse) { - .stackPane[data-expanded='true'] { flex-basis: 156px; min-height: 156px; } - .sash { flex-basis: 14px; padding-block: 6px 7px; } -} /* The very first workbench section at the top of the tab needs no double top rule. */ .browseSection > div:first-child { border-top: 0; diff --git a/src/client/clues/tab/SectionStack.tsx b/src/client/ui/WorkbenchStack.tsx similarity index 92% rename from src/client/clues/tab/SectionStack.tsx rename to src/client/ui/WorkbenchStack.tsx index 68382c7d..b4480f1a 100644 --- a/src/client/clues/tab/SectionStack.tsx +++ b/src/client/ui/WorkbenchStack.tsx @@ -1,9 +1,10 @@ /** A vertical workbench stack. A sash redistributes only the two nearest open sections. */ import { Fragment, useEffect, useId, useRef, useState, type ReactNode } from 'react' -import { createFrameBatcher } from '../../frame-batcher.ts' -import css from './clues-tab.module.css' +import { createFrameBatcher } from '../frame-batcher.ts' +import css from './workbench-stack.module.css' -interface Section { +export interface WorkbenchStackSection { + /** Stable id; also the persistence key of this section's weight. */ id: string title: string open: boolean @@ -82,8 +83,8 @@ function Sash({ top, bottom, ratio, onPreview, onCommit }: { }} /> } -export function SectionStack({ sections, initialWeights, onResize }: { - sections: readonly Section[] +export function WorkbenchStack({ sections, initialWeights, onResize }: { + sections: readonly WorkbenchStackSection[] initialWeights?: Record onResize(weights: Record): void }): ReactNode { @@ -94,7 +95,7 @@ export function SectionStack({ sections, initialWeights, onResize }: { }))) const opened = sections.filter(section => section.open) const openWeight = opened.reduce((sum, section) => sum + (weights[section.id] ?? section.weight), 0) - let previous: Section | undefined + let previous: WorkbenchStackSection | undefined return
{sections.map(section => { const top = section.open ? previous : undefined diff --git a/src/client/ui/index.ts b/src/client/ui/index.ts index f36861df..169e3c7e 100644 --- a/src/client/ui/index.ts +++ b/src/client/ui/index.ts @@ -9,6 +9,7 @@ export { } from './kit.tsx' export { LoadingIndicator, type LoadingIndicatorProps } from './LoadingIndicator.tsx' export { WorkbenchSection, type WorkbenchSectionProps } from './WorkbenchSection.tsx' +export { WorkbenchStack, type WorkbenchStackSection } from './WorkbenchStack.tsx' export { SelectMenu, type SelectMenuProps, type SelectOption } from './SelectMenu.tsx' export { TextInput, TextArea, NumberInput, Checkbox, ToggleSwitch, Tabs, SettingRow, type TabOption } from './controls.tsx' export { diff --git a/src/client/ui/workbench-stack.module.css b/src/client/ui/workbench-stack.module.css new file mode 100644 index 00000000..6d648d93 --- /dev/null +++ b/src/client/ui/workbench-stack.module.css @@ -0,0 +1,29 @@ +/** A vertical workbench stack: adjacent open sections share the height through a draggable sash. */ +.stack { + display: flex; + flex: 1; + flex-direction: column; + min-height: 0; + min-width: 0; + overflow-y: auto; +} +.stackPane { display: flex; flex: none; min-width: 0; } +.stackPane[data-expanded='true'] { flex: 1 0 112px; min-height: 112px; } +.sash { + position: relative; + flex: 0 0 7px; + cursor: row-resize; + touch-action: none; + outline: none; + box-sizing: border-box; + padding-block: 3px; + background: var(--dsw-alias-border-l2) content-box; +} +.sash + .stackPane > div > div:first-child { border-top: 0; } +.sash:hover, .sash:focus-visible, .sash:active { + background-color: var(--ds-sidebar-accent); +} +@media (pointer: coarse) { + .stackPane[data-expanded='true'] { flex-basis: 156px; min-height: 156px; } + .sash { flex-basis: 14px; padding-block: 6px 7px; } +} diff --git a/tests/changes-tab.spec.tsx b/tests/changes-tab.spec.tsx index 62b8666a..de885cbd 100644 --- a/tests/changes-tab.spec.tsx +++ b/tests/changes-tab.spec.tsx @@ -155,9 +155,15 @@ function mockGraphEmpty(): void { }) } +/** The bottom pane's own resize handle. The Git lens stacks Changes and Graph + * behind a section sash, so a bare `[role="separator"]` query would now hit + * that sash first: the section sash carries `aria-controls`, the pane handle + * does not, which is what tells them apart. */ +const PREVIEW_HANDLE = '[role="separator"]:not([aria-controls])' + /** The open bottom pane's frame: the drag handle's parent (the pane root). */ function paneOf(container: HTMLElement): HTMLElement { - const handle = container.querySelector('[role="separator"]') + const handle = container.querySelector(PREVIEW_HANDLE) expect(handle, 'the bottom pane frame is open').not.toBeNull() return handle!.parentElement as HTMLElement } @@ -829,7 +835,7 @@ describe('ChangesTab', () => { expect(row).not.toBeNull() await act(async () => { row!.click() }) await flushEffects() - return container.querySelector('[role="separator"]')?.parentElement?.style.height + return container.querySelector(PREVIEW_HANDLE)?.parentElement?.style.height } finally { act(() => { root.unmount() }) container.remove() @@ -914,7 +920,9 @@ describe('ChangesTab', () => { expect(rule('.gitScroll')).toContain('overflow-x: hidden') expect(rule('.gitScroll')).toContain('flex: 1') expect(rule('.gitScroll')).toContain('flex-direction: column') - expect(rule('.changesSection')).toContain('flex: none') + // The two sections now share one stack: each fills the height the sash + // hands it, while .gitScroll stays the panel's single scroller for notices. + expect(rule('.changesSection')).toContain('flex: 1') expect(rule('.graphSection')).toContain('flex: 1') expect(rule('.graphArea')).toContain('flex: 1') expect(rule('.graphArea')).not.toContain('height: min(') @@ -986,7 +994,7 @@ describe('ChangesTab bottom pane tabs', () => { // ONE region: a single drag handle, and the strip row is its sibling // INSIDE that same frame (the header's lens control is outside it). The // row carries the tablist and the pane's close button. - expect(container.querySelectorAll('[role="separator"]')).toHaveLength(1) + expect(container.querySelectorAll(PREVIEW_HANDLE)).toHaveLength(1) const pane = paneOf(container) expect(pane.children[0]!.getAttribute('role')).toBe('separator') expect(pane.children[1]!.querySelector('[role="tablist"]')).not.toBeNull() @@ -1084,7 +1092,7 @@ describe('ChangesTab bottom pane tabs', () => { await act(async () => { row.click() }) await flushEffects() - expect(container.querySelectorAll('[role="separator"]')).toHaveLength(1) + expect(container.querySelectorAll(PREVIEW_HANDLE)).toHaveLength(1) const pane = paneOf(container) // Same strip as everywhere else — the lens above does not change it. expect(paneTabs(container).map(tab => tab.textContent)).toEqual([t('graphDetails'), t('changesContentTab'), t('changesDiffTab')]) @@ -1292,7 +1300,7 @@ describe('ChangesTab bottom pane tabs', () => { expect(paneOf(container).querySelector(`section[aria-label="${t('graphDetails')}"]`)).not.toBeNull() await act(async () => { closeButtons()[0]!.click() }) await settle() - expect(container.querySelector('[role="separator"]')).toBeNull() + expect(container.querySelector(PREVIEW_HANDLE)).toBeNull() } finally { act(() => { root.unmount() }) container.remove() diff --git a/tests/clues-section-stack.spec.tsx b/tests/clues-section-stack.spec.tsx index c7cacc02..53185687 100644 --- a/tests/clues-section-stack.spec.tsx +++ b/tests/clues-section-stack.spec.tsx @@ -3,7 +3,7 @@ import { createElement } from 'react' import { act } from 'react-dom/test-utils' import { expect, it, vi } from 'vitest' -import { SectionStack } from '../src/client/clues/tab/SectionStack.tsx' +import { WorkbenchStack } from '../src/client/ui/WorkbenchStack.tsx' import { renderRoot, setupReactAct } from './test-utils.ts' setupReactAct() @@ -12,7 +12,7 @@ it('resizes a pair without moving the third or unmounting it when collapsed', () const commit = vi.fn() const sections = ['first', 'second', 'third'].map(id => ({ id, title: id, open: true, weight: 1, content: createElement('input', { 'aria-label': id, defaultValue: id }) })) - const view = renderRoot(createElement(SectionStack, { sections, onResize: commit })) + const view = renderRoot(createElement(WorkbenchStack, { sections, onResize: commit })) try { const separators = () => Array.from(view.container.querySelectorAll('[role="separator"]')) const press = (node: HTMLElement, key: string) => { @@ -26,7 +26,7 @@ it('resizes a pair without moving the third or unmounting it when collapsed', () expect(firstResize.third).toBe(1) const input = view.container.querySelector('[aria-label="second"]')! input.value = 'retained draft' - view.rerender(createElement(SectionStack, { sections: sections.map(section => section.id === 'second' + view.rerender(createElement(WorkbenchStack, { sections: sections.map(section => section.id === 'second' ? { ...section, open: false } : section), onResize: commit })) expect(separators()).toHaveLength(1) expect(separators()[0]!.getAttribute('aria-label')).toBe('first / third') @@ -35,7 +35,7 @@ it('resizes a pair without moving the third or unmounting it when collapsed', () expect(secondResize.first).toBeCloseTo(0) expect(secondResize.second).toBe(firstResize.second) expect(secondResize.third).toBeCloseTo(3) - view.rerender(createElement(SectionStack, { sections, onResize: commit })) + view.rerender(createElement(WorkbenchStack, { sections, onResize: commit })) expect(view.container.querySelector('[aria-label="second"]')).toBe(input) expect(input.value).toBe('retained draft') expect(separators()).toHaveLength(2) diff --git a/tests/git-scm.spec.tsx b/tests/git-scm.spec.tsx index 9cb730f8..3a0b09a2 100644 --- a/tests/git-scm.spec.tsx +++ b/tests/git-scm.spec.tsx @@ -303,3 +303,29 @@ it('checks out a plain branch and refreshes placeholder, resources, graph and fo expect(vi.mocked(api.gitGraph).mock.calls.length).toBeGreaterThan(graphCalls) } finally { view.unmount() } }) + +it('stacks Changes and Graph behind one draggable sash and drops it when a section folds', async () => { + const view = await mount(() => tracked()) + try { + const { container } = view + const separators = (): HTMLElement[] => [...container.querySelectorAll('[role="separator"]')] + expect(separators()).toHaveLength(1) + const sash = separators()[0]! + expect(sash.getAttribute('aria-orientation')).toBe('horizontal') + const [topId, bottomId] = sash.getAttribute('aria-controls')!.split(' ') + const top = document.getElementById(topId!)! + const bottom = document.getElementById(bottomId!)! + expect(top.contains(container.querySelector('[data-scm-section="changes"]'))).toBe(true) + expect(bottom.contains(container.querySelector('[data-scm-section="graph"]'))).toBe(true) + const grow = (el: HTMLElement): number => Number.parseFloat(el.style.flexGrow) + const before = grow(top) + act(() => { sash.dispatchEvent(new KeyboardEvent('keydown', { key: 'ArrowDown', bubbles: true })) }) + // The sash hands the next slice of the pair to the pane below it. + expect(grow(top)).toBeGreaterThan(before) + expect(grow(bottom)).toBeLessThan(grow(top)) + // One open section leaves nothing to divide: the sash goes away with it. + const graph = container.querySelector('[data-scm-section="graph"] button[aria-expanded]')! + await click(graph) + expect(separators()).toHaveLength(0) + } finally { view.unmount() } +})