R2021b - code folding in switch/case not fully available
38 views (last 30 days)
I've moved from R2021a to R2021b, and I have an issue with code folding in the editor for switch/case statements.
In the R2021a editor, I could fold the entire "switch...end" block, and it was also possible to separately fold the code block associated with each "case", see below:
Now, with R2021b, I can see how to fold the entire "switch...end" code clock, but I do not see anymore the possibility of folding each "case", see below:
I checked the Editor preferences, but I could not find any specific option to enable/disable code folding of "case" blocks. I could only find the option related to the entire swith
Do you know how to enable the possibility of folding each "case" in R2021b?
Prateek Rai on 13 Oct 2021
The case folding wasn't removed intentionally. MATLAB has switched to a new editor from R2021b and so, it has a new backend for the code folding data. The editor does not recognize switch case branches as a foldable construct.
The concerned development team is aware of the same and the feature might be available in a future MATLAB release.
More Answers (2)
Samuel Scott on 8 Mar 2022
I'd just like to add my two cents. This omission in the new editor is very problematic for our code base. We use many switch-case blocks and make use of code folding for more rapidly navigating the code base. Since the new update this is now impossible and all the added scrolling makes for much slower development. Personally I don't think the %% is a great solution and look forward to this being remedied in a future version.
Prateek Rai on 9 Oct 2021
To my understanding, you want to fold each "case" block in R2021b.
One possible workaround could be-
Step 1: Go to Editor preferences and enable Code Folding for "Sections" and "Switch/case blocks".
Step 2: Now you can use %% to create sections after each "case" blocks and this will give you an option for folding them.
The code will look like:
int i =1
This time you will get the option for code folding after each case.