@@ -6,6 +6,7 @@ import {computeLineInformation, DiffInformation, DiffMethod, DiffType, LineInfor
66import computeStyles , { ReactDiffViewerStyles , ReactDiffViewerStylesOverride , } from './styles' ;
77import { ReactElement } from "react" ;
88import { computeHiddenBlocks } from "./compute-hidden-blocks" ;
9+ import IntrinsicElements = React . JSX . IntrinsicElements ;
910
1011const m = require ( 'memoize-one' ) ;
1112
@@ -174,17 +175,31 @@ class DiffViewer extends React.Component<
174175 renderer ?: ( chunk : string ) => JSX . Element ,
175176 ) : ReactElement [ ] => {
176177 return diffArray . map ( ( wordDiff , i ) : JSX . Element => {
177- return (
178- < span
178+ const content = renderer ? renderer ( wordDiff . value as string ) : wordDiff . value
179+
180+ return wordDiff . type === DiffType . ADDED ?
181+ < ins
179182 key = { i }
180183 className = { cn ( this . styles . wordDiff , {
181184 [ this . styles . wordAdded ] : wordDiff . type === DiffType . ADDED ,
185+ } ) }
186+ >
187+ { content }
188+ </ ins >
189+ : wordDiff . type === DiffType . REMOVED ? < del
190+ key = { i }
191+ className = { cn ( this . styles . wordDiff , {
182192 [ this . styles . wordRemoved ] : wordDiff . type === DiffType . REMOVED ,
183193 } ) }
184194 >
185- { renderer ? renderer ( wordDiff . value as string ) : wordDiff . value }
195+ { content }
196+ </ del > : < span
197+ key = { i }
198+ className = { cn ( this . styles . wordDiff ) }
199+ >
200+ { content }
186201 </ span >
187- ) ;
202+ ;
188203 } ) ;
189204 } ;
190205
@@ -218,16 +233,24 @@ class DiffViewer extends React.Component<
218233 const removed = type === DiffType . REMOVED ;
219234 const changed = type === DiffType . CHANGED ;
220235 let content ;
221- if ( Array . isArray ( value ) ) {
236+ const hasWordDiff = Array . isArray ( value )
237+ if ( hasWordDiff ) {
222238 content = this . renderWordDiff ( value , this . props . renderContent ) ;
223239 } else if ( this . props . renderContent ) {
224240 content = this . props . renderContent ( value ) ;
225241 } else {
226242 content = value ;
227243 }
228244
245+ let ElementType : keyof IntrinsicElements = 'div'
246+ if ( added && ! hasWordDiff ) {
247+ ElementType = 'ins'
248+ } else if ( removed && ! hasWordDiff ) {
249+ ElementType = 'del'
250+ }
251+
229252 return (
230- < div className = { this . styles . line } role = { 'row' } >
253+ < ElementType className = { this . styles . line } role = { 'row' } title = { added && ! hasWordDiff ? "Added line" : removed && ! hasWordDiff ? "Removed line" : undefined } >
231254 { ! this . props . hideLineNumbers && (
232255 < div
233256 onClick = {
@@ -297,7 +320,7 @@ class DiffViewer extends React.Component<
297320 >
298321 < pre className = { this . styles . contentText } > { content } </ pre >
299322 </ div >
300- </ div >
323+ </ ElementType >
301324 ) ;
302325 } ;
303326
@@ -589,17 +612,19 @@ class DiffViewer extends React.Component<
589612 [ this . styles . splitView ] : splitView ,
590613 } ) }
591614 >
592- < div className = { this . styles . column } role = { 'table' } >
615+ < div className = { this . styles . column } role = { 'table' } title = { `Diff information for ${ leftTitle } ` } >
593616 < div
594617 className = { cn ( this . styles . titleBlock , this . styles . column ) }
618+ role = { 'columnheader' }
595619 >
596620 < pre className = { this . styles . contentText } > { leftTitle } </ pre >
597621 </ div >
598622 { nodes . leftLines }
599623 </ div >
600- { nodes . rightLines . length > 0 ? < div className = { this . styles . column } role = { 'table' } >
624+ { nodes . rightLines . length > 0 ? < div className = { this . styles . column } role = { 'table' } title = { `Diff information for ${ rightTitle } ` } >
601625 < div
602626 className = { cn ( this . styles . titleBlock , this . styles . column ) }
627+ role = { 'columnheader' }
603628 >
604629 < pre className = { this . styles . contentText } > { rightTitle } </ pre >
605630 </ div >
0 commit comments