microsoft / microsoft/monaco-editor
Is there an initialized or ready event?
Nobody has claimed this yet.
- Dominant language
- JavaScript
- Stars
- 46.8k
- Forks
- 4.1k
- Avg merge
- 17h 58m
- Merged PRs (30d)
- 1
Description
Hello,
I'm curious if there's an initialized or ready event or something I can listen to when instantiating an editor?
Would be useful in the below case for example:
<script>
require.config({ paths: { "vs": "node_modules/monaco-editor/min/vs" } });
require(["vs/editor/editor.main"], function() {
monaco.languages.json.jsonDefaults.setDiagnosticsOptions({
validate: false,
allowComments: false
});
var editor = monaco.editor.create(document.getElementById("container"), {
value: '{ "prop": "Hello world" }',
language: "json",
theme: "vs-dark",
contextmenu: false,
quickSuggestions: false,
automaticLayout: true
});
editor.getAction("editor.action.format").run();
});
</script>
Here the line editor.getAction("editor.action.format").run(); doesn't have any effect. The JSON doesn't get formatted and I assume it's because the editor is not fully initialized at that point.
I know I can solve it with setTimeout, but I was wondering if there's any other option.
Thanks in advance, keep up the good work :)
UPDATE:
Adding the below solves it, not the most beautiful solution though :)
var didScrollChangeDisposable = editor.onDidScrollChange(function(event) {
didScrollChangeDisposable.dispose();
editor.getAction("editor.action.format").run();
});
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with the AMD require callback and the call to monaco.editor.create shown in the issue. Reproduce whether editor.getAction("editor.action.format").run() works immediately, compare it with the onDidScrollChange workaround, and inspect the editor initialization lifecycle. Done means the initialization state or supported event is documented or exposed clearly enough to trigger formatting reliably.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- javascript
- Domain
- frontend
- Issue type
- Feature
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100