Skip to content

Commit

Permalink
improve text edit mode
Browse files Browse the repository at this point in the history
  • Loading branch information
lhns committed Feb 28, 2023
1 parent 5e5adda commit 76f1f7b
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 4 deletions.
4 changes: 2 additions & 2 deletions src/JsonEditorListComponent.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -56,10 +56,10 @@ class JsonEditorListComponent extends React.Component<{
<div className="flex-fill list-json-editor-panel">
<ScrollPane>
<div className="p-2">
{selectedIndex != null && (data?.entries ?? [])[selectedIndex] ?
{selectedIndex != null && data?.entries?.[selectedIndex] != null ?
<JsonEditorComponent
schema={{$schema: schema?.$schema, ...(schema?.properties?.entries?.items ?? {})}}
data={(data?.entries ?? [])[selectedIndex]}
data={data?.entries?.[selectedIndex]}
onChange={entryData => onChange({
...data,
entries: (data?.entries ?? []).map((entry: any, i: number) => selectedIndex == i ? entryData : entry)
Expand Down
4 changes: 2 additions & 2 deletions src/JsonEditorTextComponent.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,13 @@ class JsonEditorTextComponent extends React.Component<{
componentDidUpdate(prevProps: any) {
const {data} = this.props

if (data !== prevProps.data) {
if (JSON.stringify(data) !== JSON.stringify(prevProps.data)) {
this.setState(state => ({...state, value: JSON.stringify(data, null, 2)}))
}
}

render() {
const {schema, data, onChange} = this.props
const {data, onChange} = this.props
const {value} = this.state ?? {}

return data != null ? <Editor
Expand Down

0 comments on commit 76f1f7b

Please sign in to comment.