suren-atoyan / monaco-react

Monaco Editor for React - use the monaco-editor in any React application without needing to use webpack (or rollup/parcel/etc) configuration files / plugins
https://monaco-react.surenatoyan.com/
MIT License
3.81k stars 268 forks source link

Format code first time is not work but second time is work! #634

Open zhangwei900808 opened 4 months ago

zhangwei900808 commented 4 months ago

Describe the bug default language is 'json' when I set value and 'html' to language in Editor then I format code is not work,but second time is worked!

To Reproduce

Steps to reproduce the behavior:

1、set defaultLanguage={'json'}

<Editor height="calc(100vh - 216px)"
                    onMount={(editor, monaco) => handleEditorDidMount(editor, monaco, 'response')}
                    loading={''}
                    defaultLanguage={'json'}
                    options={} />

2、click format button is not work

editorResponseRef.current.updateOptions({readOnly: false});
monacoResponseRef.current.editor.setModelLanguage(editorResponseRef.current.getModel(), 'html');
editorResponseRef.current.setValue(res.payload.data)

await editorResponseRef.current.getAction('editor.action.formatDocument').run();
editorResponseRef.current.updateOptions({readOnly: true});

3、when I click secode time is work!

Expected behavior fisrt time to format code is work!

Screenshots

image image

Desktop (please complete the following information):