monaco-editor version: 0.13.1
Browser: electron (chromion? chrome?)
OS: Windows
Steps or JS usage snippet reproducing the issue:
const editor = monaco.editor.create(element[0], {
value: text,
language: mode,
automaticLayout: true,
autoIndent: true,
contextmenu: false,
formatOnType: true
});
editor.updateOptions({ readOnly: true})
editor.updateOptions({ readOnly: fasle})
editor.trigger('any', 'editor.action.formatDocument');
The problem seems to be that I am switching back to readOnly mode before the formatting has finished.
If I change my code to switch back to readOnly 300 milliseconds after triggerring the format, everything works.
Is there a way to pass a callback to the format trigger, or to catch and event that the formatting has finished?
You could use editor.getAction('editor.action.formatDocument').run().then(() => console.log('finished'));
This works great!
Most helpful comment
You could use
editor.getAction('editor.action.formatDocument').run().then(() => console.log('finished'));