Signed-off-by: soupette <cyril.lpz@gmail.com>
This commit is contained in:
cyril lopez 2021-01-26 11:09:49 +01:00 committed by GitHub
parent 54af039f17
commit 8b39f5ac05
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -29,7 +29,7 @@ class InputJSON extends React.Component {
constructor(props) { constructor(props) {
super(props); super(props);
this.editor = React.createRef(); this.editor = React.createRef();
this.state = { error: false, markedText: null, hasInitValue: false }; this.state = { error: false, markedText: null };
} }
componentDidMount() { componentDidMount() {
@ -54,7 +54,7 @@ class InputJSON extends React.Component {
} }
componentDidUpdate(prevProps) { componentDidUpdate(prevProps) {
if (prevProps.value !== this.props.value && !this.state.hasInitValue) { if (prevProps.value !== this.props.value && !this.codeMirror.state.focused) {
this.setInitValue(); this.setInitValue();
} }
} }
@ -65,9 +65,9 @@ class InputJSON extends React.Component {
try { try {
if (value === null) return this.codeMirror.setValue(''); if (value === null) return this.codeMirror.setValue('');
this.setState({ hasInitValue: true }); const nextValue = typeof value !== 'string' ? stringify(value, null, 2) : value;
return this.codeMirror.setValue(stringify(value, null, 2)); return this.codeMirror.setValue(nextValue);
} catch (err) { } catch (err) {
return this.setState({ error: true }); return this.setState({ error: true });
} }
@ -119,8 +119,6 @@ class InputJSON extends React.Component {
return; return;
} }
this.setState({ hasInitValue: true });
const { name, onChange } = this.props; const { name, onChange } = this.props;
let value = doc.getValue(); let value = doc.getValue();