Page 1 of 1

Smart brackets / parentheses deletes parenthesis

Posted: Sun Jan 23, 2022 12:12 pm
by guyr

I'm fixing up somebody else's old code. I encountered an odd scenario which I was able to narrow down using this example:

printf("Maximum of 0 and 6: %d\n", std::max(0, 6); // required closing parenthesis is missing

In Settings - Preferences - Edit, if the value "Smart brackets / parentheses" is checked, then if the cursor is between the '6' and ')' inside std::max(), and I type a right parenthesis, the editor will ignore that keystroke and simply move the cursor to the right. If instead the cursor is between the ')' and ';' , the editor will insert that character. Took me awhile to isolate why this was happening.

On the Preferences page, for the "Smart brackets / parentheses" option, the help text says: "When typing ']' or ')' next to a ']' or ')' Move the caret one position to the right". So perhaps this is the desired behavior, but for me at least this behavior was unexpected. Could the editor insert the character, AND move the caret one position to the right? Replacing a purposely typed character with caret movement doesn't seem like the right thing to do. I've unchecked this option, and now the editor is more predictable.

Thanks.


Re: Smart brackets / parentheses deletes parenthesis

Posted: Mon Jan 24, 2022 3:10 pm
by Jarod42

I would say it is the expected behavior.

Opening (,[,{ would add the closing part (at least in some context).
To avoid the double closing, there is this "smart" option.

(I disable it too BTW).