✨ feat(vscode): 代码阅读预览标出新增 / 修改 / 删除的卡片(左侧改动色条、新增淡绿底挂小标、删掉的块原位收成一行可展开),筛选栏第二行写对比基准和改动统计,新文件顶部横幅

This commit is contained in:
cruldra committed 2026-09-30 08:41:55 +08:00
1 parent 2a5806c6b5
commit 3b7ce69842
10 files changed
+491 -20

No files matched your search

@@ -0,0 +1,48 @@
import type { ReactElement } from 'react'
import type { DocumentDiff } from './types'
import { FilePlus, GitCompare } from 'lucide-react'
import { Fragment } from 'react'
import { statsParts } from './diffView'
/**
* 筛选栏第二行(标差异时才有):对比基准(「对比:上一次提交」),改动统计(「新增 2 · 修改 3 · 删除 1」,各按改动色,
* 没有的那种不写,都没有写「没有改动」)。基准里没有这个文件时不写统计,看横幅。
*/
export function DiffBar({ diff }: { diff: DocumentDiff }): ReactElement {
const parts = statsParts(diff.stats)
return (
<div className="mx-auto box-content flex h-[30px] max-w-[880px] items-center gap-2 px-6 text-xs whitespace-nowrap text-[var(--vscode-descriptionForeground)]">
<GitCompare size={14} strokeWidth={1.8} className="shrink-0" aria-hidden />
<span className="min-w-0 truncate">
对比:
<span className="text-[var(--vscode-foreground)]">{diff.base}</span>
</span>
{diff.newFile === undefined && (
<>
<span className="opacity-60" aria-hidden>·</span>
<span className="flex items-center gap-1.5">
{parts.length === 0
? '没有改动'
: parts.map((part, index) => (
<Fragment key={part.change}>
{index > 0 && <span aria-hidden>·</span>}
<span className="cr-diff-stat" data-change={part.change}>{part.text}</span>
</Fragment>
))}
</span>
</>
)}
</div>
)
}
/** 基准里没有这个文件(新文件、未跟踪的):预览顶部一条横幅,卡片不再逐张标绿。 */
export function NewFileBanner({ detail }: { detail: string }): ReactElement {
return (
<div className="cr-new-file mb-3 flex items-center gap-2 rounded-md px-3 py-[7px]" role="status">
<FilePlus size={16} strokeWidth={1.8} className="shrink-0" aria-hidden />
<span className="shrink-0 text-[12.5px] leading-[18px] font-medium text-[var(--vscode-foreground)]">新文件,全部是新增</span>
<span className="min-w-0 text-xs leading-[18px] text-[var(--vscode-descriptionForeground)]">{detail}</span>
</div>
)
}