0
votes

Problem I am trying to use react-monaco-editor to render a json code. When I try to format the json , I was suggested the method: editor.getAction('editor.action.formatDocument').run() . The code that I use is

const editorDidMount = (editor, monaco) => {
    setTimeout(() => {
      console.log(editor);
      editor.getAction('editor.action.formatDocument').run()
    }, 300);
  };

but I get the following error: Uncaught TypeError: Cannot read property 'run' of null Could some one please help me understand why I am missing getAction method in the editor instance.

One other thing that I noticed is that, when checking in the context-menu(right-click).. I dont see the Format Document. Aslo the action editor.action.formatDocument is missing in the _actions object of the editor instance. Any help is much appreciated.

1

1 Answers

-1
votes

This seems to be an issue created by myself. I had to add the option format in the list of features of the monaco-editor-webpack-plugin(https://github.com/microsoft/monaco-editor-webpack-plugin). But one downside is I still cannot find the editor.getAction() method. Instead I had to use the editor.trigger() method to simulate a format action throught code.