Skip to content

Commit

Permalink
feat(ui): add token diff support in diff view (#19983)
Browse files Browse the repository at this point in the history
Signed-off-by: linghaoSu <[email protected]>
  • Loading branch information
linghaoSu authored Sep 18, 2024
1 parent 2a199bc commit e09ff60
Showing 1 changed file with 8 additions and 2 deletions.
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import * as React from 'react';
import {useState} from 'react';
import {Diff, Hunk} from 'react-diff-view';
import {Diff, Hunk, tokenize, markEdits} from 'react-diff-view';
import 'react-diff-view/style/index.css';

import './application-resources-diff.scss';
Expand All @@ -15,6 +15,12 @@ export interface IndividualDiffSectionProps {
export const IndividualDiffSection = (props: IndividualDiffSectionProps) => {
const {file, showPath, whiteBox, viewType} = props;
const [collapsed, setCollapsed] = useState(false);
const options = {
highlight: false,
enhancers: [markEdits(file.hunks, {type: 'block'})]
};
const token = tokenize(file.hunks, options);

return (
<div className={`${whiteBox} application-component-diff__diff`}>
{showPath && (
Expand All @@ -24,7 +30,7 @@ export const IndividualDiffSection = (props: IndividualDiffSectionProps) => {
</p>
)}
{!collapsed && (
<Diff viewType={viewType} diffType={file.type} hunks={file.hunks}>
<Diff viewType={viewType} diffType={file.type} hunks={file.hunks} tokens={token}>
{(hunks: any) => hunks.map((hunk: any) => <Hunk className={'custom-diff-hunk'} key={hunk.content} hunk={hunk} />)}
</Diff>
)}
Expand Down

0 comments on commit e09ff60

Please sign in to comment.