Align value preview style with code editor
This commit is contained in:
@@ -15,7 +15,7 @@ interface Props {
|
|||||||
}
|
}
|
||||||
|
|
||||||
class CodeDiff extends React.Component<Props, {}> {
|
class CodeDiff extends React.Component<Props, {}> {
|
||||||
private handleCtrlA = selectTextWithCtrlA({ targetSelector: 'pre' })
|
private handleCtrlA = selectTextWithCtrlA({ targetSelector: 'pre ~ pre' })
|
||||||
|
|
||||||
constructor(props: Props) {
|
constructor(props: Props) {
|
||||||
super(props)
|
super(props)
|
||||||
@@ -71,7 +71,7 @@ class CodeDiff extends React.Component<Props, {}> {
|
|||||||
if (hasStyledCode && this.props.language === 'json') {
|
if (hasStyledCode && this.props.language === 'json') {
|
||||||
const currentLines = styledLines.slice(lineNumber, lineNumber + changedLines)
|
const currentLines = styledLines.slice(lineNumber, lineNumber + changedLines)
|
||||||
const lines = currentLines.map((html: string, idx: number) => {
|
const lines = currentLines.map((html: string, idx: number) => {
|
||||||
return <div key={`${key}-${idx}`} className={this.props.classes.line}><span className={this.cssClassForChange(change)} dangerouslySetInnerHTML={{ __html: html }} /></div>
|
return <div key={`${key}-${idx}`} className={`${this.props.classes.line} ${this.cssClassForChange(change)}`}><span dangerouslySetInnerHTML={{ __html: html }} /></div>
|
||||||
})
|
})
|
||||||
lineNumber += changedLines
|
lineNumber += changedLines
|
||||||
|
|
||||||
@@ -81,16 +81,25 @@ class CodeDiff extends React.Component<Props, {}> {
|
|||||||
return this.trimNewlineRight(change.value)
|
return this.trimNewlineRight(change.value)
|
||||||
.split('\n')
|
.split('\n')
|
||||||
.map((line, idx) => {
|
.map((line, idx) => {
|
||||||
return <div key={`${key}-${idx}`} className={this.props.classes.line}><span className={this.cssClassForChange(change)}>{line}</span></div>
|
return <div key={`${key}-${idx}`} className={`${this.props.classes.line} ${this.cssClassForChange(change)}`}><span>{line}</span></div>
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
|
const gutters = changes.map((change, key) => {
|
||||||
|
return this.trimNewlineRight(change.value)
|
||||||
|
.split('\n')
|
||||||
|
.map((_, idx) => (
|
||||||
|
<div key={`${key}-${idx}`} className={`${this.cssClassForChange(change)} ${this.props.classes.gutterLine}`}>
|
||||||
|
{change.added ? '+' : null}{change.removed ? '-' : null}{!change.added && !change.removed ? ' ' : null}
|
||||||
|
</div>
|
||||||
|
))
|
||||||
|
})
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div>
|
<div>
|
||||||
<div className={this.props.classes.gutters} tabIndex={0} onKeyDown={this.handleCtrlA}>
|
<div tabIndex={0} onKeyDown={this.handleCtrlA}>
|
||||||
<pre className={`language-json ${this.props.classes.codeBlock}`}>
|
<pre className={this.props.classes.gutters}>{gutters}</pre>
|
||||||
{code}
|
<pre className={this.props.classes.codeBlock}>{code}</pre>
|
||||||
</pre>
|
|
||||||
</div>
|
</div>
|
||||||
{this.renderChangeAmount(changes)}
|
{this.renderChangeAmount(changes)}
|
||||||
</div>
|
</div>
|
||||||
@@ -103,10 +112,6 @@ const style = (theme: Theme) => {
|
|||||||
const baseStyle = {
|
const baseStyle = {
|
||||||
width: '100%',
|
width: '100%',
|
||||||
}
|
}
|
||||||
const before = {
|
|
||||||
margin: '0 2px 0 -9px',
|
|
||||||
color: codeBlockColors.text,
|
|
||||||
}
|
|
||||||
|
|
||||||
return {
|
return {
|
||||||
additions: {
|
additions: {
|
||||||
@@ -116,15 +121,24 @@ const style = (theme: Theme) => {
|
|||||||
color: 'rgb(255, 10, 10)',
|
color: 'rgb(255, 10, 10)',
|
||||||
},
|
},
|
||||||
line: {
|
line: {
|
||||||
lineHeight: 'normal',
|
lineHeight: 'normal' as 'normal',
|
||||||
|
paddingLeft: '4px',
|
||||||
|
},
|
||||||
|
gutterLine: {
|
||||||
|
textAlign: 'right' as 'right',
|
||||||
|
paddingRight: theme.spacing(0.5),
|
||||||
},
|
},
|
||||||
gutters: {
|
gutters: {
|
||||||
backgroundColor: codeBlockColors.gutters,
|
backgroundColor: codeBlockColors.gutters,
|
||||||
|
width: '33px',
|
||||||
|
display: 'inline-block' as 'inline-block',
|
||||||
|
font: "12px/normal 'Monaco', 'Menlo', 'Ubuntu Mono', 'Consolas', 'source-code-pro', monospace",
|
||||||
|
userSelect: 'none' as 'none',
|
||||||
},
|
},
|
||||||
codeBlock: {
|
codeBlock: {
|
||||||
fontSize: '12px',
|
display: 'inline-block' as 'inline-block',
|
||||||
maxHeight: '200px',
|
width: 'calc(100% - 33px)',
|
||||||
marginLeft: '33px !important',
|
font: "12px/normal 'Monaco', 'Menlo', 'Ubuntu Mono', 'Consolas', 'source-code-pro', monospace",
|
||||||
backgroundColor: `${codeBlockColors.background} !important`,
|
backgroundColor: `${codeBlockColors.background} !important`,
|
||||||
'& span': {
|
'& span': {
|
||||||
color: codeBlockColors.text,
|
color: codeBlockColors.text,
|
||||||
@@ -153,17 +167,10 @@ const style = (theme: Theme) => {
|
|||||||
},
|
},
|
||||||
noChange: {
|
noChange: {
|
||||||
...baseStyle,
|
...baseStyle,
|
||||||
'&:before': {
|
|
||||||
...before,
|
|
||||||
},
|
|
||||||
},
|
},
|
||||||
deletion: {
|
deletion: {
|
||||||
...baseStyle,
|
...baseStyle,
|
||||||
backgroundColor: 'rgba(255, 10, 10, 0.3)',
|
backgroundColor: 'rgba(255, 10, 10, 0.3)',
|
||||||
'&:before': {
|
|
||||||
...before,
|
|
||||||
content: "'-'",
|
|
||||||
},
|
|
||||||
'&:hover': {
|
'&:hover': {
|
||||||
backgroundColor: 'rgba(255, 10, 10, 0.6)',
|
backgroundColor: 'rgba(255, 10, 10, 0.6)',
|
||||||
},
|
},
|
||||||
@@ -174,10 +181,6 @@ const style = (theme: Theme) => {
|
|||||||
'&:hover': {
|
'&:hover': {
|
||||||
backgroundColor: 'rgba(10, 255, 10, 0.5)',
|
backgroundColor: 'rgba(10, 255, 10, 0.5)',
|
||||||
},
|
},
|
||||||
'&:before': {
|
|
||||||
...before,
|
|
||||||
content: "'+'",
|
|
||||||
},
|
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user