Merge pull request #1240 from omdsh-dev/fix/git-detail-close-button

fix(changes): Git 详情面板的关闭按钮常驻 Tabs 行最右侧(#991)
This commit is contained in:
Hairy authored and GitHub committed 2026-11-21 20:47:27 +08:00
commit 14219fa9d6
10 files changed
+115 -17

No files matched your search

+3
View File
@@ -4,6 +4,9 @@
### 未发布
- 🧷 **Git 详情面板的关闭按钮常驻在 Tabs 同一行的最右侧**([#991](https://github.com/omdsh-dev/DSH-better-sidebar/issues/991)):底部面板的「提交详情 / 内容 / 差异」是一条 Tabs,但关闭整块面板的 X 原先画在「内容 / 差异」的页内头行上——切到「提交详情」时它整条头行都不渲染,于是那个页签根本没有关闭入口,只能先切页签再点 X。现在关闭按钮属于 Tabs 那一行:无论选中哪个页签都停在最右端、位置不变,点击关闭的是整块面板;「内容 / 差异」头行里那个重复的 X 已移除。只有一个视图、没有 Tabs 行的预览仍保持原来的头行位置。
- 🧪 测试:`tests/changes-tab.spec.tsx` 逐个页签断言面板里**只有一个**关闭按钮、它挂在 Tabs 那一行且排在 tablist 之后(行尾),并从「提交详情」页签点击它关闭整块面板。
- 🧷 **空白新会话在右侧栏展开时仍能打开底部工作台**([#989](https://github.com/omdsh-dev/DSH-better-sidebar/issues/989)):blank 会话里宿主不渲染会话头 utilities,插件的底部工作台入口只剩右上角那一个备用入口;而它在宿主右侧面板展开时整个不渲染,于是「先开右栏」就再也打不开底部工作台(#1053 修的是正常会话的会话头入口,这一处当时被留了下来)。现在展开态照常渲染,并改锚**面板左缘**——那一格是会话头那一行的右端空位,与收起态入口同一列,不压面板内容。
- 🧪 测试:`tests/dock-fallback.spec.tsx` 把「展开态不渲染」改成「展开态渲染且锚在面板左缘(756px)」并断言点击仍能打开;`tests/e2e/blank-session-dock-entry.e2e.ts` 新增真实宿主用例:空白会话展开右栏后入口仍在、屏上恰好一个、右缘不越过面板左缘、点击打开底部面板。
+3
View File
@@ -6,6 +6,9 @@
### Unreleased
- 🧷 **The Git details pane's close button now sits permanently at the right end of the tab row** ([#991](https://github.com/omdsh-dev/DSH-better-sidebar/issues/991)): the bottom pane's "commit details / content / diff" strip is one tab row, but the X that closes the whole pane was drawn inside the content/diff head — a row that does not render at all on the details tab, so that tab had no exit and closing meant switching views first. The button now belongs to the tab row: it stays at the right end on every tab, never moves, and closes the whole pane; the duplicate X inside the content/diff head is gone. A single-view preview with no tab row keeps its previous head placement.
- 🧪 Tests: `tests/changes-tab.spec.tsx` asserts, per tab, that the pane holds exactly one close button, that it rides the tab row after the tablist (the row's right end), and that clicking it from the details tab closes the whole pane.
- 🧷 **A blank new session can still open the bottom workbench while the right panel is expanded** ([#989](https://github.com/omdsh-dev/DSH-better-sidebar/issues/989)): a blank session draws no session-header utilities, so the plugin's only bottom-workbench opener is the corner fallback entry — and that entry rendered nothing at all while the host's right panel was expanded, which made the workbench unreachable once the panel was opened first (#1053 fixed this for the header entry in ordinary sessions and left this one behind). It now renders in the expanded state too and anchors to the **panel's left edge**: that slot is the free right end of the conversation-header row, the same column as the collapsed-state entry, so it never covers panel content.
- 🧪 Tests: `tests/dock-fallback.spec.tsx` turns "renders nothing while expanded" into "renders while expanded, anchored at the panel's left edge (756px)" and asserts the click still opens the workbench; `tests/e2e/blank-session-dock-entry.e2e.ts` adds a real-host case: after expanding the right column on a blank session the entry is still there, exactly one on screen, its right edge stays left of the panel, and clicking it opens the bottom panel.
Binary file not shown.

After

Width:  |  Height:  |  Size: 11 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 11 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 6.6 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 6.7 KiB

+29 -8
View File
@@ -15,6 +15,11 @@
* views the caller hosts (the graph commit's `details` card) sit ahead of
* both. A read op has no `diff` tab — nothing changed. With one or zero tabs
* the pane is byte-for-byte the strip-less preview of before.
*
* Closing the pane is ONE action, not a per-view one: while the strip is up,
* its right end carries the pane's close button, so the exit sits on the same
* row as the tabs and never moves or disappears with the active view. A
* strip-less preview keeps the button in the diff head (its only row).
*/
import { useEffect, useMemo, useRef, useState, type PointerEvent as ReactPointerEvent, type ReactNode } from 'react'
import { IconCloseOutlineRegular, IconFolderOpenOutlineRegular, IconRefreshOutlineRegular, IconRightUpOutlineRegular, IconShareOutlineRegular, MarkdownDelegateProvider, MarkdownText } from '@deepseek-ai/dsh-client-ui-primitives'
@@ -124,7 +129,9 @@ export interface PaneTab {
* the only tab stop, and Left/Right/Home/End move focus AND selection (the
* standard automatic-activation model). Born as the bottom pane's strip
* (details / diff). Rendered only when the caller hosts more than one view,
* so a diff-only preview never grows a strip.
* so a diff-only preview never grows a strip. It is the flexible half of the
* pane's strip row: the row's own chrome (border, padding, the close button
* after it) belongs to the caller, not to the tablist.
*/
export function PaneTabStrip(props: { tabs: readonly PaneTab[]; active: string; onSelect(id: string): void; className?: string; label?: string }) {
const buttons = useRef<(HTMLButtonElement | null)[]>([])
@@ -528,7 +535,26 @@ export function DiffPane({ target, ctx, scope, height, onHeightCommit, onClose,
}}
/>
)
const strip = hasStrip ? <PaneTabStrip tabs={allTabs} active={active} onSelect={onSelectTab ?? (() => {})} /> : null
/** The pane's ONE close affordance. While the strip is up it rides the
* strip row's right end (see `strip`), so closing the pane never depends on
* which view is on screen; a strip-less preview keeps it in the diff head,
* its only row. */
const closeButton = (
<IconButton
size="sm"
icon={<IconCloseOutlineRegular size={14} />}
label={t('changesClosePreview')}
onClick={onClose}
/>
)
const strip = hasStrip
? (
<div className={css.paneStrip}>
<PaneTabStrip tabs={allTabs} active={active} onSelect={onSelectTab ?? (() => {})} />
{closeButton}
</div>
)
: null
// A caller-hosted view (the graph commit's card) takes over the head AND
// the body: same frame, same handle, same height behaviour — only the
@@ -671,12 +697,7 @@ export function DiffPane({ target, ctx, scope, height, onHeightCommit, onClose,
onClick={() => { setContentRaw(value => !value) }}
/>
)}
<IconButton
size="sm"
icon={<IconCloseOutlineRegular size={14} />}
label={t('changesClosePreview')}
onClick={onClose}
/>
{hasStrip ? null : closeButton}
</div>
{active === 'content'
? (hasContentTab ? contentBody : <PaneEmpty text={t('changesNoContent')} />)
+11 -6
View File
@@ -674,12 +674,16 @@
.dragHandle::after { content: ''; position: absolute; left: calc(50% - 18px); top: 3px; width: 36px; height: 2px; border-radius: 1px; background: var(--dsw-alias-border-l2); }
.dragHandle:hover::after, .dragHandle:focus-visible::after { background: var(--dsw-alias-state-business-primary); }
/* ── Bottom pane tab strip (VS Code-style panel) ───────────────────────────
Only rendered when the pane really hosts two views (a graph commit's
`details` + its diff); a diff-only preview keeps the strip-less head. The
strip sits under the drag handle, so the handle stays the pane's top edge
and the strip doubles as the row that names the active view. */
.paneTabs { flex: none; display: flex; align-items: center; gap: 2px; height: 28px; padding: 0 8px; border-bottom: 1px solid var(--dsw-alias-border-l1); }
/* ── Bottom pane strip row (VS Code-style panel) ───────────────────────────
Rendered when the pane really hosts two views or more (the changes tab pins
`details` / `content` / `diff`); a diff-only preview keeps the strip-less
head. The row sits under the drag handle, so the handle stays the pane's top
edge, and the row doubles as the pane's own header: the tablist takes the
free width, the pane's close button is pinned to the right end. Closing the
pane is not a per-view action, so the exit stays on this row for every tab
instead of moving into the view body. */
.paneStrip { flex: none; display: flex; align-items: center; gap: 2px; height: 28px; padding: 0 8px; border-bottom: 1px solid var(--dsw-alias-border-l1); }
.paneTabs { flex: 1 1 auto; min-width: 0; display: flex; align-items: center; gap: 2px; height: 100%; }
.paneTab {
align-self: stretch;
display: inline-flex;
@@ -690,6 +694,7 @@
background: transparent;
color: var(--dsw-alias-label-secondary);
font: var(--dsw-font-xxxs-strong-11);
white-space: nowrap;
cursor: pointer;
}
.paneTab:hover { background: var(--dsw-alias-interactive-bg-hover); color: var(--dsw-alias-label-primary); }
+55 -3
View File
@@ -983,12 +983,13 @@ describe('ChangesTab bottom pane tabs', () => {
await flushEffects()
await openGraphCommit(container)
// ONE region: a single drag handle, and the strip is its sibling INSIDE
// that same frame (the header's lens control is outside it).
// 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)
const pane = paneOf(container)
expect(pane.children[0]!.getAttribute('role')).toBe('separator')
expect(pane.children[1]!.getAttribute('role')).toBe('tablist')
expect(pane.children[1]!.querySelector('[role="tablist"]')).not.toBeNull()
const tabs = paneTabs(container)
expect(tabs.map(tab => tab.textContent)).toEqual([t('graphDetails'), t('changesContentTab'), t('changesDiffTab')])
// Details is the default for the FIRST graph selection; roving tabIndex
@@ -1247,4 +1248,55 @@ describe('ChangesTab bottom pane tabs', () => {
container.remove()
}
})
/**
* The pane's exit is ONE control on the strip row, not a per-view action.
* Before #991 the only X lived in the diff/content head — below the tabs, and
* absent entirely on the details tab, so closing the pane meant switching
* views first. Now the strip row's right end carries it on every tab, and no
* view body renders a second one.
*/
it('keeps ONE close button at the right end of the strip row on every tab, and it closes the pane', async () => {
mockGit([])
mockGraph()
const container = document.createElement('div')
document.body.append(container)
const root: Root = createRoot(container)
const closeLabel = t('changesClosePreview')
/** The row the tablist and the close button share. */
const stripRow = (): HTMLElement =>
paneOf(container).querySelector<HTMLElement>('[role="tablist"]')!.parentElement as HTMLElement
const closeButtons = (): HTMLButtonElement[] =>
[...paneOf(container).querySelectorAll<HTMLButtonElement>(`button[aria-label="${closeLabel}"]`)]
try {
mount(root)
await flushEffects()
await openGraphCommit(container)
for (const index of [0, 1, 2]) {
await act(async () => { paneTabs(container)[index]!.click() })
await settle()
const buttons = closeButtons()
// Exactly one exit in the whole pane: no second one in the view head.
expect(buttons).toHaveLength(1)
// It rides the strip row, AFTER the tablist (the row's right end).
expect(buttons[0]!.parentElement).toBe(stripRow())
expect(stripRow().firstElementChild!.getAttribute('role')).toBe('tablist')
expect(stripRow().lastElementChild).toBe(buttons[0])
}
// The details tab — the view that had no exit at all — closes the pane.
await act(async () => { paneTabs(container)[0]!.click() })
await settle()
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()
} finally {
act(() => { root.unmount() })
container.remove()
}
})
})
+14
View File
@@ -78,6 +78,20 @@ test('read-only Git Graph renders merge history and filters without checkout', a
const mergeRow = graph.locator('[data-graph-commit]', { hasText: 'Graph merge' }).first()
await expect(mergeRow.getByText('main', { exact: true })).toBeVisible()
await page.screenshot({ path: testInfo.outputPath('git-graph.png'), fullPage: true })
// #991: the pane's exit is ONE control on the tab row — the details tab
// used to have no close button at all, and the diff/content views carried
// theirs BELOW the strip. It now rides the strip row's right end on every
// tab, and clicking it closes the whole pane.
const paneRoot = page.locator('[class*="diffPane"]').first()
const tabRow = paneRoot.locator('[role="tablist"]').first().locator('..')
const closeButton = tabRow.getByRole('button', { name: 'Close preview', exact: true })
await expect(closeButton).toHaveCount(1)
await paneRoot.getByRole('tab', { name: 'Diff', exact: true }).click()
await expect(tabRow.getByRole('button', { name: 'Close preview', exact: true })).toHaveCount(1)
// …and it is the pane's ONLY one (no second X left in the diff head).
await expect(paneRoot.getByRole('button', { name: 'Close preview', exact: true })).toHaveCount(1)
await closeButton.click()
await expect(paneRoot).toHaveCount(0)
const branchFilter = page.locator('[data-git-graph] select').filter({ has: page.locator('option[value="refs/heads/feature"]') })
await branchFilter.selectOption('refs/heads/feature')
await expect(graph.getByText('Graph merge', { exact: true })).toHaveCount(0)