Monaco-editor: Once an editor has become read only no formatting can happen, even if switched back to read only = false

Created on 27 Jul 2018  路  3Comments  路  Source: microsoft/monaco-editor


monaco-editor version: 0.13.1
Browser: electron (chromion? chrome?)
OS: Windows
Steps or JS usage snippet reproducing the issue:

  • Create an editor.
const editor = monaco.editor.create(element[0], {
            value: text,
            language: mode,
            automaticLayout: true,
            autoIndent: true,
            contextmenu: false,
            formatOnType: true
        });
  • Switch to read only
editor.updateOptions({ readOnly: true})
  • Switch back to readOnly = false
editor.updateOptions({ readOnly: fasle})
  • Execute formatting - No formatting happens
editor.trigger('any', 'editor.action.formatDocument');

Most helpful comment

You could use editor.getAction('editor.action.formatDocument').run().then(() => console.log('finished'));

All 3 comments

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!

Was this page helpful?
0 / 5 - 0 ratings

Related issues

robclive picture robclive  路  3Comments

PinkyJie picture PinkyJie  路  3Comments

Kang-Jun-sik picture Kang-Jun-sik  路  3Comments

andreymarchenko picture andreymarchenko  路  3Comments

Panhaiwei picture Panhaiwei  路  3Comments