Sublime Forum

Help with broken / changed code folding in C#

#1

Hi all,

So, I’ve noticed in the last year something changed in sublime text and C# code folding has broken ( or changed) to the point that it only seems to work with wrapping methods directly.

I became accustomed to code folding #region code as well as custom “/// —>” lines which really helped to clean up my code. This has become second nature to me after working with sublime text for many years and I would like to get them working again. BTW: the old code-folding approaches actually still work if I set the file type from C# to “Plain Text” in the bottom right of the sublime text window, but then I obviously lose color syntax which is even worse.

So the short question is, is there any way to use C# color syntax with the code-folding functionality of “Plain Text” ( as that seems to work fine ).

Any help would be much appreciated!

Thanks!

EDIT: Replaced “Code-wrapping” to “code-folding”.

0 Likes

#2

Word wrap has always been disabled for source scope, while being enabled in text.

The behavior is controlled by "word_wrap": "auto", setting.

To enable word wrapping in C# you probably want to set "word_wrap": true, in syntax-specific settings.

0 Likes

#3

Hi @deathaxe

Appreciate the reply. To clarify, I am not talking about word wrapping but rather “code wrapping”. When you can wrap blocks of code with the little arrows next to the line numbers on the left.

I’m assuming that’s a different setting?

0 Likes

#4

You mean code folding?

0 Likes

#5

Yep - my apologies :slight_smile:

(EDIT: Updated thread title )

0 Likes

#6

ST4143+ supports syntax based code folding.

C# has been configured to use syntax based folding, with the assumption it beeing the more appropriate approach.

Feedback from various users revealed disabling indentation based folding is unfortune depending on various code styles and workflows.

Unfortunatelly a general PR to revert that change has more or less been rejected (see: https://github.com/sublimehq/Packages/pull/3617)

You have 2 options to re-enable it:

  1. Create an override for Packages/C#/Fold.tmPreferences with the related line removed
    see: https://github.com/sublimehq/Packages/blob/e5d24630f6533a84940983e113198825f37364d5/C%23/Fold.tmPreferences#L8-L9

    This way both engines would do their job next to each other. I personally like the way how braces are folded by syntax based folding.

  2. Set "fold_style": "force_indentation" in syntax specific settings or global Preferences to revert to old ST3 behaviour.

0 Likes

#7

Hi @deathaxe,

Thanks for the info! Much appreciated.

I just tried 2 ( as it seemed to be the easiest fix ) but that doesn’t seem to change how the code folding is working for me - unless I’m missing something obvious?

Steps I took:
went to Settings… > Settings - Syntax Specific

The whole thing on the right looks like this:

// These settings override both User and Default settings for the C# syntax
{
“fold_style”: “force_indentation”
}

0 Likes

#8

I missed to say the setting is supported as of ST4145+. So if you are still on stable channel (ST4143), option 1) is the only one available.

0 Likes

#9

Hi @deathaxe,

Just downloaded the dev build and it works!

Thanks a lot for providing the solution - I know it’s probably a personal preference thing, but it was really making me consider switching away from Sublime because it was annoying me so much, haha.

Happy that I don’t need to do that anymore! :slight_smile:

Thanks again!

1 Like