[@monaco-editor/react] formatDocument is not working
See original GitHub issueI am trying to format the json text present in the Editor using editorDidMount method, but its not working when readOnly option is set as true.
I am using @monaco-editor/react": “^3.2.1”
PFA the code snippet. Any work around or suggestions will be helpful
const editorDidMount = (_valueGetter: any, editor: any) => {
if (editor) {
setTimeout(function() {
editor.getAction('editor.action.formatDocument').run();
}, 300);
}
};
<Editor
language={props.language}
value={props.data.payload || ''}
height={'300px'}
options={{
readOnly: true,
autoIndent: 'full',
automaticLayout: true,
minimap: {
enabled: false,
},
wordWrap: 'on',
formatOnPaste: true,
formatOnType: true,
}}
editorDidMount={editorDidMount}
/>
Issue Analytics
- State:
- Created a year ago
- Comments:5 (2 by maintainers)
Top Results From Across the Web
json automatic formatting · Issue #89 · react-monaco-editor ...
problem I used JSON.stringif to format the json, and set it to the value property, but it will not auto format document.
Read more >how to format format a piece of codes - monaco editor
I am going to make a SQL editor which is not a built-in language. If you try to make "Format Document" and "Format...
Read more >@monaco-editor/react - npm
Start using @monaco-editor/react in your project by running `npm i @monaco-editor/react`. There are 315 other projects in the npm registry ...
Read more >Monaco Editor component for React.
React Monaco Editor ... MonacoEditor component for React. ... This library is supported for use in Windows Tailored Apps only. Build: 6.2.8100.0.
Read more >Monaco Editor Playground
Press Chord Ctrl-K, Ctrl-M => the action will run if it is enabled. editor.addAction({. // An unique identifier of the contributed action.
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Hi @rainy789, Thanks for the code snippet. It works!
The following workaround works.