fix(git-lens): 分支条与提交框移出滚动体,只有列表内层滚动(#194)

This commit is contained in:
Menghuan1918 committed 2026-10-05 22:13:00 +08:00
1 parent 39e7b587d8
commit 97ba41d441
3 files changed
+224 -112

No files matched your search

+114 -104
View File
@@ -863,9 +863,12 @@ export function GitLens(props: GitLensProps) {
)
return (
<div className={css.git}>
<div className={css.git} data-git-root>
{/* The non-scrolling head: the branch / repository / worktree band stays
on screen while the change list and the history scroll under it
(#194). */}
{(repoChoices.length > 1 || worktrees.length > 1 || branch !== '') && (
<div className={css.selectors}>
<div className={css.selectors} data-git-head>
{repoChoices.length > 1 && (
<select
className={css.select}
@@ -908,66 +911,120 @@ export function GitLens(props: GitLensProps) {
</div>
)}
{viewError !== null && <Notice kind="error" role="alert">{viewError}</Notice>}
{/* The ONE scroll body: the change groups and the history scroll here,
between the fixed head band and the fixed commit bar (#194). */}
<div className={css.gitScroll} data-git-scroll>
{viewError !== null && <Notice kind="error" role="alert">{viewError}</Notice>}
{snapshot === null && status.loading && <Notice kind="loading" tone="page">{t('loading')}</Notice>}
{snapshot === null && !status.loading && status.error && <Notice kind="error" tone="page">{t('error')}</Notice>}
{snapshot !== null && !isRepo && <Notice kind="empty" tone="page">{t('notRepo')}</Notice>}
{snapshot?.truncated === true && <Notice kind="warn">{t('statusTruncated')}</Notice>}
{snapshot === null && status.loading && <Notice kind="loading" tone="page">{t('loading')}</Notice>}
{snapshot === null && !status.loading && status.error && <Notice kind="error" tone="page">{t('error')}</Notice>}
{snapshot !== null && !isRepo && <Notice kind="empty" tone="page">{t('notRepo')}</Notice>}
{snapshot?.truncated === true && <Notice kind="warn">{t('statusTruncated')}</Notice>}
{clean && <Notice kind="empty" tone="page">{t('changesClean')}</Notice>}
{clean && <Notice kind="empty" tone="page">{t('changesClean')}</Notice>}
{isRepo && !clean && (
<>
{/* Each group is its own block so its sticky header is released (and
replaced) exactly when the group scrolls away. */}
<div className={css.group} data-group="unstaged">
<SectionHeader
className={css.groupHeader}
label={t('unstaged')}
action={unstagedEntries.length > 0
? (
<IconButton
className={css.headerAction}
size="sm"
disabled={busy}
label={t('stageAll')}
icon={<IconPlusOutlineRegular size={14} />}
onClick={() => { stageAll(false) }}
/>
)
: undefined}
>
<span className={css.countPill} data-count={unstagedEntries.length}>{unstagedEntries.length}</span>
</SectionHeader>
{renderTree(unstagedTree, false)}
</div>
<div className={css.group} data-group="staged">
<SectionHeader
className={css.groupHeader}
label={t('staged')}
action={stagedEntries.length > 0
? (
<IconButton
className={css.headerAction}
size="sm"
disabled={busy}
label={t('unstageAll')}
icon={<IconTrashOutlineRegular size={14} />}
onClick={() => { stageAll(true) }}
/>
)
: undefined}
>
<span className={css.countPill} data-count={stagedEntries.length}>{stagedEntries.length}</span>
</SectionHeader>
{renderTree(stagedTree, true)}
</div>
</>
)}
{isRepo && !clean && (
<>
{/* Each group is its own block so its sticky header is released (and
replaced) exactly when the group scrolls away. */}
<div className={css.group} data-group="unstaged">
<SectionHeader
className={css.groupHeader}
label={t('unstaged')}
action={unstagedEntries.length > 0
? (
<IconButton
className={css.headerAction}
size="sm"
disabled={busy}
label={t('stageAll')}
icon={<IconPlusOutlineRegular size={14} />}
onClick={() => { stageAll(false) }}
/>
)
: undefined}
>
<span className={css.countPill} data-count={unstagedEntries.length}>{unstagedEntries.length}</span>
</SectionHeader>
{renderTree(unstagedTree, false)}
</div>
<div className={css.group} data-group="staged">
<SectionHeader
className={css.groupHeader}
label={t('staged')}
action={stagedEntries.length > 0
? (
<IconButton
className={css.headerAction}
size="sm"
disabled={busy}
label={t('unstageAll')}
icon={<IconTrashOutlineRegular size={14} />}
onClick={() => { stageAll(true) }}
/>
)
: undefined}
>
<span className={css.countPill} data-count={stagedEntries.length}>{stagedEntries.length}</span>
</SectionHeader>
{renderTree(stagedTree, true)}
</div>
</>
)}
{isRepo && (
<>
<SectionHeader label={t('history')} count={logEntries.length > 0 ? logEntries.length : undefined} />
{logEntries.length === 0 && logFailed && <Notice kind="error">{t('historyLoadError')}</Notice>}
{logEntries.length === 0 && !logFailed && logEnded && <Notice kind="empty" tone="page">{t('changesNoHistory')}</Notice>}
{logEntries.map(entry => (
<div
key={entry.hashFull}
role="button"
tabIndex={0}
className={css.logRow}
data-selected={selectedRef?.kind === 'commit' && selectedRef.hashFull === entry.hashFull ? 'true' : undefined}
title={`${entry.author} · ${entry.date}\n${entry.hashFull}`}
onClick={() => { onPreview(commitRefOf(entry)) }}
onKeyDown={(event) => {
if (event.key === 'Enter' || event.key === ' ') {
event.preventDefault()
onPreview(commitRefOf(entry))
}
}}
onContextMenu={(event) => { openHistoryMenu(event, entry) }}
>
<span className={css.logLine1}>
<span className={css.logHash}>{entry.hash}</span>
<span className={css.logSubject}>{entry.subject}</span>
</span>
<span className={css.logLine2}>
{refNames(entry.refs).map(ref => (
<span key={ref} className={css.logRef}>{ref}</span>
))}
<span className={css.logMeta}>{entry.author} · {relativeTime(entry.date)}</span>
</span>
</div>
))}
{!logEnded && (
<button
type="button"
className={css.logMore}
disabled={logLoadingMore || busy}
onClick={() => { void loadMoreLog() }}
>
{logLoadingMore ? t('loading') : t('loadMore')}
</button>
)}
</>
)}
</div>
{/* The commit bar is OUTSIDE the scroll body: it is the tab's persistent
action surface, so the message being written never scrolls away
(#194). */}
{isRepo && (
<div className={css.commitBar}>
<div className={css.commitBar} data-commit-bar>
<div className={css.commitRow}>
<span className={css.commitInputWrap}>
{/* A native textarea (the primitives ship no multiline input):
@@ -1036,53 +1093,6 @@ export function GitLens(props: GitLensProps) {
</div>
)}
{isRepo && (
<>
<SectionHeader label={t('history')} count={logEntries.length > 0 ? logEntries.length : undefined} />
{logEntries.length === 0 && logFailed && <Notice kind="error">{t('historyLoadError')}</Notice>}
{logEntries.length === 0 && !logFailed && logEnded && <Notice kind="empty" tone="page">{t('changesNoHistory')}</Notice>}
{logEntries.map(entry => (
<div
key={entry.hashFull}
role="button"
tabIndex={0}
className={css.logRow}
data-selected={selectedRef?.kind === 'commit' && selectedRef.hashFull === entry.hashFull ? 'true' : undefined}
title={`${entry.author} · ${entry.date}\n${entry.hashFull}`}
onClick={() => { onPreview(commitRefOf(entry)) }}
onKeyDown={(event) => {
if (event.key === 'Enter' || event.key === ' ') {
event.preventDefault()
onPreview(commitRefOf(entry))
}
}}
onContextMenu={(event) => { openHistoryMenu(event, entry) }}
>
<span className={css.logLine1}>
<span className={css.logHash}>{entry.hash}</span>
<span className={css.logSubject}>{entry.subject}</span>
</span>
<span className={css.logLine2}>
{refNames(entry.refs).map(ref => (
<span key={ref} className={css.logRef}>{ref}</span>
))}
<span className={css.logMeta}>{entry.author} · {relativeTime(entry.date)}</span>
</span>
</div>
))}
{!logEnded && (
<button
type="button"
className={css.logMore}
disabled={logLoadingMore || busy}
onClick={() => { void loadMoreLog() }}
>
{logLoadingMore ? t('loading') : t('loadMore')}
</button>
)}
</>
)}
{/*
The one shared file-row context menu, positioned at the right-click
cursor (portal so the panel's overflow clip cannot crop it).
+21 -8
View File
@@ -18,15 +18,29 @@
/* ── Git lens (the former git panel) ───────────────────────────────────── */
/* The Git lens ROOT is not a scroller (#194): it is the fixed frame that holds
the non-scrolling head band (branch / repository / worktree pickers) above
the ONE inner scroll body and the commit bar below it. Everything that used
to scroll here — the change groups, the history, the state lines — now
scrolls inside `.gitScroll`, so the branch bar and the commit box stay on
screen while the list moves. */
.git {
flex: 1;
min-height: 0;
min-width: 0;
display: flex;
flex-direction: column;
}
/* The inner scroll body: the change groups + the history. It owns both scroll
axes' policy — vertical scrolling for the list, clipping for anything wider
than the panel (tab pages never scroll horizontally: content wraps or
truncates to the panel width instead of panning sideways). */
.gitScroll {
flex: 1;
min-height: 0;
min-width: 0;
overflow-y: auto;
/* Tab pages never scroll horizontally: content wraps or truncates to the
panel width instead of panning sideways. */
overflow-x: hidden;
}
@@ -191,14 +205,13 @@
.row:not(:hover):not(:focus-within) .rowAction { opacity: 1; }
}
/* ── Commit bar (docked to the bottom edge of the scroll area) ─────────── */
/* ── Commit bar (docked below the scroll body, never inside it) ─────────── */
/* Since #194 the bar is a SIBLING of `.gitScroll` in the lens root's column:
it is always on screen, so it needs neither `position: sticky` nor a
stacking order over the sticky group headers (they are inside the scroller,
which clips them). */
.commitBar {
position: sticky;
bottom: 0;
/* Above the sticky group headers: the commit bar is the surface the user
interacts with when they scroll to the bottom of the list. */
z-index: 3;
flex: none;
display: flex;
flex-direction: column;
+89
View File
@@ -11,6 +11,7 @@
*/
// @vitest-environment jsdom
import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest'
import { readFileSync } from 'node:fs'
import { createElement } from 'react'
import { createRoot, type Root } from 'react-dom/client'
import { act } from 'react-dom/test-utils'
@@ -415,6 +416,94 @@ describe('ChangesTab', () => {
expect(await paneHeightFor(50)).toBe('140px')
})
/**
* Issue #194: the branch band and the commit box must not scroll away with
* the list. The lens root is therefore a FIXED frame whose only scrollable
* child is the list body holding the change groups and the history — the two
* chrome bands are its siblings, not its contents.
*/
it('keeps the branch band and the commit bar outside the one scroll body (#194)', async () => {
mockGit([{ path: 'src/a.ts', xy: ' M' }])
vi.spyOn(api, 'gitLog').mockResolvedValue([{
hash: 'abcdef0',
hashFull: 'abcdef0abcdef0abcdef0abcdef0abcdef0abcd',
subject: 'history row',
author: 'Test',
date: '2026-08-20 00:00:00 +0800',
refs: 'HEAD -> main',
}])
const container = document.createElement('div')
document.body.append(container)
const root: Root = createRoot(container)
try {
mount(root)
await flushEffects()
const frame = container.querySelector<HTMLElement>('[data-git-root]')
const scroller = container.querySelector<HTMLElement>('[data-git-scroll]')
const head = container.querySelector<HTMLElement>('[data-git-head]')
const bar = container.querySelector<HTMLElement>('[data-commit-bar]')
expect(frame).not.toBeNull()
expect(scroller).not.toBeNull()
expect(head).not.toBeNull()
expect(bar).not.toBeNull()
// The frame is NOT the scroller: the root must never carry the scroll body.
expect(frame!.hasAttribute('data-git-scroll')).toBe(false)
// The branch band and the commit bar are the frame's own children, so
// neither can be carried out of the viewport by the list scrolling.
expect(head!.parentElement).toBe(frame)
expect(bar!.parentElement).toBe(frame)
expect(scroller!.contains(head!)).toBe(false)
expect(scroller!.contains(bar!)).toBe(false)
// The list body is what actually holds the change list and the history.
expect(scroller!.querySelector('[data-group="unstaged"] [data-path="src/a.ts"]')).not.toBeNull()
const historyRow = scroller!.querySelector<HTMLElement>('[role="button"]')
expect(historyRow).not.toBeNull()
expect(historyRow!.textContent).toContain('history row')
// The commit box is inside its bar, and the bar sits BELOW the scroller.
const input = container.querySelector('textarea')
expect(input).not.toBeNull()
expect(scroller!.contains(input!)).toBe(false)
expect(bar!.contains(input!)).toBe(true)
expect(scroller!.compareDocumentPosition(bar!) & Node.DOCUMENT_POSITION_FOLLOWING).toBeTruthy()
} finally {
act(() => { root.unmount() })
container.remove()
}
})
it('scrolls the inner body only and no longer pins the commit bar with position: sticky (#194)', () => {
// jsdom has no layout engine, so the sheet itself is the evidence for the
// docking mechanic (the same pattern the explorer's batch bar uses).
const sheet = readFileSync('src/client/changes/changes.module.css', 'utf8')
const rule = (selector: string): string => {
const block = sheet.match(new RegExp(`\\n\\${selector} \\{([\\s\\S]*?)\\n\\}`))?.[1]
expect(block, `the ${selector} rule must exist in changes.module.css`).toBeDefined()
return block!
}
// The lens root is the fixed frame: it owns no scroll axis at all.
expect(rule('.git')).not.toContain('overflow')
expect(rule('.git')).toContain('display: flex')
// The inner body is the ONE vertical scroller (and clips the width).
expect(rule('.gitScroll')).toContain('overflow-y: auto')
expect(rule('.gitScroll')).toContain('overflow-x: hidden')
expect(rule('.gitScroll')).toContain('flex: 1')
// The commit bar is now a plain flex sibling — no sticky bottom, no
// stacking order over the (still sticky) group headers.
expect(rule('.commitBar')).not.toContain('position')
expect(rule('.commitBar')).not.toContain('sticky')
expect(rule('.commitBar')).not.toContain('z-index')
// The group headers still park on the inner body's top edge.
const groupHeader = rule('.group .groupHeader')
expect(groupHeader).toContain('position: sticky')
expect(groupHeader).toContain('top: 0')
})
it('polls the session events only while the session lens is on screen', async () => {
vi.useFakeTimers()
mockGit([])