mirror of
https://gitee.com/baidu/amis.git
synced 2024-11-29 18:48:45 +08:00
fix: DiffEditor 抽成组件后onChange异常问题 (#11086)
This commit is contained in:
parent
2b699bf7e6
commit
8624ec5468
@ -22,6 +22,8 @@ export default class DiffEditor extends React.Component<DiffEditorProps> {
|
||||
}
|
||||
|
||||
if (this.modifiedEditor && value !== prevProps.value) {
|
||||
const editorValue = this.modifiedEditor.getModel().getValue();
|
||||
editorValue !== value &&
|
||||
this.modifiedEditor.getModel().setValue(value || '');
|
||||
}
|
||||
|
||||
@ -63,6 +65,13 @@ export default class DiffEditor extends React.Component<DiffEditorProps> {
|
||||
return monaco.editor.createDiffEditor(containerElement, options);
|
||||
}
|
||||
|
||||
@autobind
|
||||
handleModifiedEditorChange(e: any) {
|
||||
const {onChange} = this.props;
|
||||
const value = this.modifiedEditor.getModel().getValue();
|
||||
onChange?.(value, e);
|
||||
}
|
||||
|
||||
@autobind
|
||||
editorDidMount(editor: any, monaco: any) {
|
||||
const {value, originValue, language, onFocus, onBlur, editorDidMount} =
|
||||
@ -92,6 +101,12 @@ export default class DiffEditor extends React.Component<DiffEditorProps> {
|
||||
}).dispose
|
||||
);
|
||||
|
||||
this.toDispose.push(
|
||||
this.modifiedEditor.onDidChangeModelContent(
|
||||
this.handleModifiedEditorChange
|
||||
).dispose
|
||||
);
|
||||
|
||||
this.editor.setModel({
|
||||
original: this.monaco.editor.createModel(originValue || '', language),
|
||||
modified: this.monaco.editor.createModel(value, language)
|
||||
|
@ -101,6 +101,7 @@ export class DiffEditorRenderer extends React.Component<
|
||||
this.handleFocus = this.handleFocus.bind(this);
|
||||
this.handleBlur = this.handleBlur.bind(this);
|
||||
this.handleEditorMounted = this.handleEditorMounted.bind(this);
|
||||
this.handleChange = this.handleChange.bind(this);
|
||||
}
|
||||
|
||||
doAction(
|
||||
|
Loading…
Reference in New Issue
Block a user