The problem seems to be partly solved. When the selection is made from up to down, indeed the bug is fixed. When selecting a few lines from bottom to top, the positioning of the surrounding brackets and sometimes also the alignment of the code are still incorrect.