CodeEditor: making sure we trigger the latest onSave callback provided to the component (#39835)

This commit is contained in:
Marcus Andersson 2021-10-07 08:51:23 +02:00 committed by GitHub
parent d09cdfb844
commit d9ca3c5c5d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -86,6 +86,13 @@ class UnthemedCodeEditor extends React.PureComponent<Props> {
}
};
onSave = () => {
const { onSave } = this.props;
if (onSave) {
onSave(this.getEditorValue());
}
};
handleBeforeMount = (monaco: Monaco) => {
this.monaco = monaco;
const { language, theme, getSuggestions, onBeforeEditorMount } = this.props;
@ -99,15 +106,10 @@ class UnthemedCodeEditor extends React.PureComponent<Props> {
};
handleOnMount = (editor: MonacoEditorType, monaco: Monaco) => {
const { onSave, onEditorDidMount } = this.props;
const { onEditorDidMount } = this.props;
this.getEditorValue = () => editor.getValue();
if (onSave) {
editor.addCommand(monaco.KeyMod.CtrlCmd | monaco.KeyCode.KEY_S, () => {
onSave(this.getEditorValue());
});
}
editor.addCommand(monaco.KeyMod.CtrlCmd | monaco.KeyCode.KEY_S, this.onSave);
const languagePromise = this.loadCustomLanguage();
if (onEditorDidMount) {