Formatting the code

Hello,
I’m developping a javascript code editor in a web app with React.
I would like to format the code (indentations, brackets etc…) when I click on a specific button.
I Used the autoFormatRange function, but when i click on the button, it only format one line, and i have to press the button again to format another line of the selection. Very strange…
Could you help me to fix this please?

CodeMirror doesn’t come with a formatting feature. You can reindent, but that’s it.