优化文件编辑工具里多hunk的显示样式

This commit is contained in:
xintaofei
2026-03-28 16:17:21 +08:00
parent 4e5f4a382c
commit 75139a1226

View File

@@ -446,9 +446,21 @@ function rowMarker(row: ParsedDiffRow): RowMarker {
return "none" return "none"
} }
function HunkSeparator({ hunk }: { hunk: ParsedDiffHunk }) {
const label =
hunk.oldStart != null && hunk.oldCount != null
? `@@ -${hunk.oldStart},${hunk.oldCount} +${hunk.newStart ?? hunk.oldStart},${hunk.newCount ?? hunk.oldCount} @@`
: "···"
return (
<div className="flex items-center gap-2 border-y border-border/50 bg-muted/30 px-3 py-0.5 font-mono text-[11px] text-muted-foreground/60">
<span className="select-none">{label}</span>
</div>
)
}
function HunkLines({ rows }: { rows: ParsedDiffRow[] }) { function HunkLines({ rows }: { rows: ParsedDiffRow[] }) {
return ( return (
<div className="inline-block min-w-full font-mono text-[12px] leading-[20px]"> <div className="font-mono text-[12px] leading-[20px]">
{rows.map((row, i) => { {rows.map((row, i) => {
const marker = rowMarker(row) const marker = rowMarker(row)
return ( return (
@@ -540,9 +552,14 @@ export function UnifiedDiffPreview({
</header> </header>
<div className="overflow-auto"> <div className="overflow-auto">
{file.hunks.map((hunk) => ( <div className="inline-block min-w-full">
<HunkLines key={hunk.key} rows={hunk.rows} /> {file.hunks.map((hunk, hunkIdx) => (
))} <div key={hunk.key}>
{hunkIdx > 0 && <HunkSeparator hunk={hunk} />}
<HunkLines rows={hunk.rows} />
</div>
))}
</div>
</div> </div>
</section> </section>
))} ))}