Refactor CodeDiff

This commit is contained in:
Thomas Nordquist
2019-06-04 11:32:59 +02:00
parent 8cc3d416b8
commit e66f6d098a
5 changed files with 136 additions and 87 deletions

View File

@@ -0,0 +1,33 @@
export function trimNewlineRight(str: string) {
if (str.slice(-1) === '\n') {
return str.slice(0, -1)
}
return str
}
const gutterBaseStyle = {
width: '100%',
}
const additionStyle = {
...gutterBaseStyle,
backgroundColor: 'rgba(10, 255, 10, 0.3)',
}
const deletionStyle = {
...gutterBaseStyle,
backgroundColor: 'rgba(255, 10, 10, 0.3)',
}
export function lineChangeStyle(change: Diff.Change) {
if (change.added === true) {
return additionStyle
}
if (change.removed === true) {
return deletionStyle
}
return gutterBaseStyle
}