I type my code like this:
if (foo() == 42) bar(); cout << something_else << endl;
Then I think, Oh wait, there's something else I want to do if foo returns 42...
so I need a curly brace...
I put my cursor at the end of the "if" line, press enter, press backspace to de-indent, that's where my curly brace goes...
Code::Blocks gives me this:
if (foo() == 42) { } bar(); cout << something_else << endl;
This is the thing I find most annoying about coding in Code::Blocks.
(I don't know whether other IDEs do this or something else.)
It seems like it should be able to see that this is what I want:
if (foo() == 42) { bar(); } cout << something_else << endl;
If the number of lines, below the insertion of a curly brace, that are indented compared to what is above the insertion of the curly brace, is 1, then put the automatically generated close brace after that 1 line.
This is the main reason, I don't use this feature. It is pretty annoying when editing existing code.
A workaround you can use is to go to the closing curly brace and use alt-down arrow to move the line where it belongs.
I also think it is a very annoying bug.
This is sort of a feature to deal with this case. Enable "Selection brace completion" in general settings. Select anything (does not matter what) on the line with
bar()
.Type "
{
". Now you have:Not exactly what we want :/ ... but I think the extra level of indentation (select it all and shift-tab it away) is due to another piece of auto-indent code that was written without testing this feature.