Visualize diff function in video

This commit is contained in:
Thomas Nordquist
2019-03-03 15:52:34 +01:00
parent 87a86b8c0c
commit 6000541c32
8 changed files with 85 additions and 47 deletions

View File

@@ -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