Skip to content

Commit e09ff60

Browse files
authoredSep 18, 2024··
feat(ui): add token diff support in diff view (#19983)
Signed-off-by: linghaoSu <linghao.su@daocloud.io>
1 parent 2a199bc commit e09ff60

File tree

1 file changed

+8
-2
lines changed

1 file changed

+8
-2
lines changed
 

‎ui/src/app/applications/components/application-resources-diff/individual-diff-section.tsx

+8-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import * as React from 'react';
22
import {useState} from 'react';
3-
import {Diff, Hunk} from 'react-diff-view';
3+
import {Diff, Hunk, tokenize, markEdits} from 'react-diff-view';
44
import 'react-diff-view/style/index.css';
55

66
import './application-resources-diff.scss';
@@ -15,6 +15,12 @@ export interface IndividualDiffSectionProps {
1515
export const IndividualDiffSection = (props: IndividualDiffSectionProps) => {
1616
const {file, showPath, whiteBox, viewType} = props;
1717
const [collapsed, setCollapsed] = useState(false);
18+
const options = {
19+
highlight: false,
20+
enhancers: [markEdits(file.hunks, {type: 'block'})]
21+
};
22+
const token = tokenize(file.hunks, options);
23+
1824
return (
1925
<div className={`${whiteBox} application-component-diff__diff`}>
2026
{showPath && (
@@ -24,7 +30,7 @@ export const IndividualDiffSection = (props: IndividualDiffSectionProps) => {
2430
</p>
2531
)}
2632
{!collapsed && (
27-
<Diff viewType={viewType} diffType={file.type} hunks={file.hunks}>
33+
<Diff viewType={viewType} diffType={file.type} hunks={file.hunks} tokens={token}>
2834
{(hunks: any) => hunks.map((hunk: any) => <Hunk className={'custom-diff-hunk'} key={hunk.content} hunk={hunk} />)}
2935
</Diff>
3036
)}

0 commit comments

Comments
 (0)
Please sign in to comment.