0

Is there a way to get Visual Studio 2019 to preserve existing indentation when writing typing . to start typing the next field?

MyStruct a =
{
    .asd = 12,
.foo = 1,
}

While typing the following code, as soon as I type . for the foo field with the cursor right under . in the asd field VS removes all spaces and not even Ctrl + Z gets me back on the indentation I want.

I've gone through the extensive list of options in Text Editor > C++ > Formatting > Spacing but couldn't find one to disable this behaviour.

avilapa
  • 11
  • 3
  • I wouldn't expect VS2019 to properly format a C++20 feature. – Mark Ransom Jun 09 '23 at 20:17
  • Fair point indeed – avilapa Jun 09 '23 at 20:19
  • I've just checked on my installation of VS Community 2019 version 16.11.26, and designated initializers are being formatted correctly. Maybe you just need to update to a more recent version of VS2019. – Jan Schultke Jun 09 '23 at 20:21
  • Just tried latest 2019 and 2022 and I'm getting this behaviour in both, even with a fresh install – avilapa Jun 09 '23 at 22:20
  • There clearly is a setting somewhere because, when I type in the code you quote, I don't get the behaviour you describe but a maintained indentation for the `.foo = ...` line. Now it's just a matter of looking for the setting that changes the behaviour ... – Adrian Mole Jun 10 '23 at 06:14

1 Answers1

0

Turns out this was caused not by Visual Studio, but by the extension Visual Assist X. Disabling "Convert dot to -> in C/C++" (in Visual Assist Options > Editor) for some reason fixes this.

avilapa
  • 11
  • 3
  • Hi, glad to know your problem has been solved! Please consider accepting it as an answer to change its status to Answered. It will also help others to solve the similar issue. – Minxin Yu - MSFT Jun 12 '23 at 01:36