Visualize diff function in video
This commit is contained in:
@@ -35,8 +35,7 @@ class CodeDiff extends React.Component<Props, {}> {
|
||||
return <div key={key}>{lines}</div>
|
||||
}
|
||||
|
||||
return change.value
|
||||
.slice(0, -1) // Remove trailing newline
|
||||
return this.trimNewlineRight(change.value)
|
||||
.split('\n')
|
||||
.map((line, idx) => {
|
||||
return <div key={`${key}-${idx}`} className={this.props.classes.line}><span className={this.cssClassForChange(change)}>{line}</span></div>
|
||||
@@ -50,6 +49,14 @@ class CodeDiff extends React.Component<Props, {}> {
|
||||
)
|
||||
}
|
||||
|
||||
private trimNewlineRight(str: string) {
|
||||
if (str.slice(-1) === '\n') {
|
||||
return str.slice(0, -1)
|
||||
}
|
||||
|
||||
return str
|
||||
}
|
||||
|
||||
private cssClassForChange(change: diff.Change) {
|
||||
if (change.added === true) {
|
||||
return this.props.classes.addition
|
||||
|
||||
Reference in New Issue
Block a user