-
Notifications
You must be signed in to change notification settings - Fork 3.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
How to indent/prettify code on load of Monaco Editor #2664
Comments
You can use I am not aware of any initialization event. See #115. |
@rcjsuen I tried your suggestion but it looks like it only works with |
I tried it in JavaScript in the playground and it seems to work. const editor = monaco.editor.create(document.getElementById("container"), {
value: "function hello(){\nalert('Hello world!');}",
language: "javascript",
"autoIndent": true,
"formatOnPaste": true,
"formatOnType": true
});
setTimeout(() => {
editor.getAction('editor.action.formatDocument').run();
}, 1000) |
You are right! Javascript work too! That's already pretty nice, cause it was the main reason why I needed it! Thank you so much my friend! One final question: I know I can select the amount of spaces/tabs to indent the code. Do you know if is possible to tell it to skip lines? Instead of:
it would do:
? |
No, I don't know how to configure the formatter or if you even can. |
It doesn't always work. For some slow pages (eg. multiple monaco editor instances), it doesn't work at all. |
None of these solutions worked for me. I'm calling editorInstance.onDidLayoutChange(() => {
requestAnimationFrame(() => {
editorInstance
.getDomNode()
?.querySelector(".editor-scrollable")
?.scroll({
behavior: "smooth",
top: 5,
});
});
}); |
Closing as duplicate of #115 |
Hi,
I am using this code:
I would like it to prettify/indent the JS code in the "value" when it loads, but it never works. I already tried using methods like
window.editor.getModel().updateOptions({ "autoIndent": true,tabSize: 2 })
but also never works. Any idea how I can make monaco editor prettify the code as it loads, indenting or adding tabs to make it more readable?The text was updated successfully, but these errors were encountered: