import { composeLen } from "@git-diff-view/core"; import { diffAsideWidthName, hunkContentBGName, hunkContentColorName, hunkLineNumberBGName, plainLineNumberColorName, } from "@git-diff-view/utils"; import { ExpandAll, ExpandDown, ExpandUp } from "./DiffExpand"; import { useDiffViewContext } from "./DiffViewContext"; import type { DiffFile } from "@git-diff-view/core"; const InternalDiffUnifiedHunkLine = ({ index, diffFile, lineNumber, }: { index: number; diffFile: DiffFile; lineNumber: number; }) => { const currentHunk = diffFile.getUnifiedHunkLine(index); const expandEnabled = diffFile.getExpandEnabled(); const { useDiffContext } = useDiffViewContext(); const enableWrap = useDiffContext.useShallowStableSelector((s) => s.enableWrap); const couldExpand = expandEnabled && currentHunk && currentHunk.unifiedInfo; const isExpandAll = currentHunk && currentHunk.unifiedInfo && currentHunk.unifiedInfo.endHiddenIndex - currentHunk.unifiedInfo.startHiddenIndex < composeLen; const isFirstLine = currentHunk && currentHunk.isFirst; const isLastLine = currentHunk && currentHunk.isLast; return ( {couldExpand ? ( isFirstLine ? ( ) : isLastLine ? ( ) : isExpandAll ? ( ) : ( <> ) ) : (
)}
{currentHunk.unifiedInfo?.plainText || currentHunk.text}
); }; export const DiffUnifiedHunkLine = ({ index, diffFile, lineNumber, }: { index: number; diffFile: DiffFile; lineNumber: number; }) => { const currentHunk = diffFile.getUnifiedHunkLine(index); const currentIsShow = currentHunk && currentHunk.unifiedInfo && currentHunk.unifiedInfo.startHiddenIndex < currentHunk.unifiedInfo.endHiddenIndex; const currentIsPureHunk = currentHunk && diffFile._getIsPureDiffRender() && !currentHunk.unifiedInfo; if (!currentIsShow && !currentIsPureHunk) return null; return ; };