davidvarga / MBeautifier

MBeautifier is a MATLAB source code formatter, beautifier. It can be used directly in the MATLAB Editor and it is configurable.
GNU General Public License v3.0
478 stars 75 forks source link

Fix indentation on MATLAB R2021b #112

Closed danielmeer closed 2 years ago

danielmeer commented 2 years ago

In MATLAB R2021b the MBeautify.formatCurrentEditorPage() and MBeautify.formatEditorSelection() functions didn't indent the code correctly anymore. It seems to be a bug in MathWorks' editorPage.smartIndentContents() function which gets triggered depending on the cursor position in the editor.

This pull request fixes the issue by indenting the code before restoring the cursor position. This was anyway a bug in the MBeautifier code, because the smart indentation resets the cursor position, making its prior restoration pointless.

The pull request also contains another improvement to the cursor restoration and a bugfix for the MBeautify.formatEditorSelection() function.