import { composeLen, type DiffFile } from "@git-diff-view/core"; import { hunkLineNumberBGName, plainLineNumberColorName, hunkContentBGName, hunkContentColorName, borderColorName, } from "@git-diff-view/utils"; import { DiffModeEnum } from ".."; import { ExpandAll, ExpandDown, ExpandUp } from "./DiffExpand"; import { useDiffViewContext } from "./DiffViewContext"; const DiffSplitHunkLineGitHub = ({ index, diffFile, lineNumber, }: { index: number; diffFile: DiffFile; lineNumber: number; }) => { const currentHunk = diffFile.getSplitHunkLine(index); const expandEnabled = diffFile.getExpandEnabled(); const couldExpand = expandEnabled && currentHunk && currentHunk.splitInfo; const isExpandAll = currentHunk && currentHunk.splitInfo && currentHunk.splitInfo.endHiddenIndex - currentHunk.splitInfo.startHiddenIndex < composeLen; const isFirstLine = currentHunk && currentHunk.isFirst; const isLastLine = currentHunk && currentHunk.isLast; return ( {couldExpand ? ( isFirstLine ? ( ) : isLastLine ? ( ) : isExpandAll ? ( ) : ( <> ) ) : (
)}
{currentHunk.splitInfo?.plainText || currentHunk.text}
); }; const DiffSplitHunkLineGitLab = ({ index, diffFile, lineNumber, }: { index: number; diffFile: DiffFile; lineNumber: number; }) => { const currentHunk = diffFile.getSplitHunkLine(index); const expandEnabled = diffFile.getExpandEnabled(); const couldExpand = expandEnabled && currentHunk && currentHunk.splitInfo; const isExpandAll = currentHunk && currentHunk.splitInfo && currentHunk.splitInfo.endHiddenIndex - currentHunk.splitInfo.startHiddenIndex < composeLen; const isFirstLine = currentHunk && currentHunk.isFirst; const isLastLine = currentHunk && currentHunk.isLast; return ( {couldExpand ? ( isFirstLine ? ( ) : isLastLine ? ( ) : isExpandAll ? ( ) : ( <> ) ) : (
)}
{currentHunk.splitInfo?.plainText || currentHunk.text}
{couldExpand ? ( isFirstLine ? ( ) : isLastLine ? ( ) : isExpandAll ? ( ) : ( <> ) ) : (
)}
{currentHunk.splitInfo?.plainText || currentHunk.text}
); }; const InternalDiffSplitHunkLine = ({ index, diffFile, lineNumber, }: { index: number; diffFile: DiffFile; lineNumber: number; }) => { const { useDiffContext } = useDiffViewContext(); const diffViewMode = useDiffContext.useShallowStableSelector((s) => s.mode); if ( diffViewMode === DiffModeEnum.SplitGitHub || diffViewMode === DiffModeEnum.Split || diffViewMode === DiffModeEnum.Unified ) { return ; } else { return ; } }; export const DiffSplitHunkLine = ({ index, diffFile, lineNumber, }: { index: number; diffFile: DiffFile; lineNumber: number; }) => { const currentHunk = diffFile.getSplitHunkLine(index); const currentIsShow = currentHunk && currentHunk.splitInfo && currentHunk.splitInfo.startHiddenIndex < currentHunk.splitInfo.endHiddenIndex; const currentIsPureHunk = currentHunk && diffFile._getIsPureDiffRender() && !currentHunk.splitInfo; if (!currentIsShow && !currentIsPureHunk) return null; return ; };