Add option to hide whitepace changes in diffs

Co-authored-by: Florian Scholdei<florian.scholdei@cloudogu.com>
Co-authored-by: René Pfeuffer<rene.pfeuffer@cloudogu.com>


Reviewed-by: Florian Scholdei <florian.scholdei@cloudogu.com>
This commit is contained in:
Viktor Egorov
2024-05-14 11:33:48 +02:00
parent e5e2fd151c
commit c8ef99cf07
37 changed files with 688 additions and 498 deletions

View File

@@ -34,17 +34,20 @@ import useScrollToElement from "../useScrollToElement";
type Props = DiffObjectProps & {
diff: FileDiff[];
fileControlFactory?: FileControlFactory;
ignoreWhitespace?: string;
};
const createKey = (file: FileDiff) => {
return `${file.oldPath}@${file.oldRevision}/${file.newPath}@${file.newRevision}`;
const createKey = (file: FileDiff, ignoreWhitespace?: string) => {
// we need to include the information about hidden whitespace in the key, because otherwise the diff might not be
// rendered correctly, if the user toggles the ignore whitespace button
return `${file.oldPath}@${file.oldRevision}/${file.newPath}@${file.newRevision}?${ignoreWhitespace}`;
};
const getAnchorSelector = (uriHashContent: string) => {
return "#" + escapeWhitespace(decodeURIComponent(uriHashContent));
};
const Diff: FC<Props> = ({ diff, ...fileProps }) => {
const Diff: FC<Props> = ({ diff, ignoreWhitespace, ...fileProps }) => {
const [t] = useTranslation("repos");
const [contentRef, setContentRef] = useState<HTMLElement | null>();
const { hash } = useLocation();
@@ -64,14 +67,14 @@ const Diff: FC<Props> = ({ diff, ...fileProps }) => {
{diff.length === 0 ? (
<Notification type="info">{t("diff.noDiffFound")}</Notification>
) : (
diff.map(file => <DiffFile key={createKey(file)} file={file} {...fileProps} />)
diff.map((file) => <DiffFile key={createKey(file, ignoreWhitespace)} file={file} {...fileProps} />)
)}
</div>
);
};
Diff.defaultProps = {
sideBySide: false
sideBySide: false,
};
export default Diff;