title: How to format code right after `setValue()` is called in the Monaco Editor?
body: <p>If you copy/paste the <code>code</code> into a Monaco Editor it gets instantly formatted due to <code>'formatOnPaste'</code>. But if you use the method <code>setValue</code>, and call the <code>"editor.action.formatDocument"</code> right after, nothing happens. I need to wrap it in a <code>setTimeout</code> Which visibly makes your code jump in the editor...</p>
  
  <p>Any suggestions? You can copy/paste + click run the code below in a <a href="https://microsoft.github.io/monaco-editor/playground.html" rel="nofollow noreferrer">playround</a></p>
  
  <pre class="lang-js prettyprint-override"><code>var value = "function hello() {\nalert('Hello world!');\n}";
  
  var instance = monaco.editor.create(document.getElementById("container"), {
      language: "javascript",
      formatOnPaste: true,
  });
  
  
  // Setup the listner for the model change
  instance.getModel().onDidChangeContent(() =&gt; {
      // !! Comment out the setTimeout, nothing wil happen..
      setTimeout(() =&gt; {
          instance.getAction("editor.action.formatDocument").run();
          // instance.trigger("", 'editor.action.formatDocument');
      }, 100);
  });
  
  // Change the value...
  instance.setValue(value);
  </code></pre>