mirror of
https://github.com/grafana/grafana.git
synced 2025-02-25 18:55:37 -06:00
CodeEditor: making sure we trigger the latest onSave callback provided to the component (#39835)
This commit is contained in:
parent
d09cdfb844
commit
d9ca3c5c5d
@ -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) {
|
||||
|
Loading…
Reference in New Issue
Block a user