sublimehq / sublime_text

Issue tracker for Sublime Text
https://www.sublimetext.com
810 stars 39 forks source link

Unfolding multiple regions in a line one-by-one #5798

Open deathaxe opened 1 year ago

deathaxe commented 1 year ago

Problem description

Considder following code snippet.

class Foo:
    def method(
        self,
        arg1 = True,
        arg2 = True,
        arg3 = True,
        arg4 = True,
    ):
        """
        This is a funciton
               :returns: nothing
        """
        pass

Folding method's parameters and body may end up in:

grafik

Unfolding via fold buttons unfolds both regions.

Unfolding via key bindings ctrl+shift+] works only, if caret is directly next to one of folded regions.

Preferred solution

Unfolding via fold buttons should unfold regions one by one beginning with the last one, maybe by default or if a modifier key is pressed.

Example:

Key binding should unfold regions one by one beginning with the last one in the same line caret is located in. Maybe a new argument for unfold command can be introduced to control its behavior.

{ "keys": ["ctrl+shift+]"], "command": "unfold", "args": {"strategy": "right_to_left" } },

Valid values for strategy:

Alternatives

It should at least be possible to unfold regions of a line without moving caret exactly to the front of a folded region.

Additional Information

No response

deathaxe commented 1 year ago

Related with #1064, which requests the modifier for fold buttons.

coodoo commented 1 year ago

@deathaxe Also is it possile to keep cursor always in view after (un)folding? Currently the viewport will jump around after (un)folding which makes it a bit annoying having to find where the cursor is in a rather long document.

Possibly related: https://github.com/sublimehq/sublime_text/issues/5622

coodoo commented 1 year ago

btw I remember it used to do it in a context-aware way, say I have three functions (A, B, C), fold all functions, move cursor to function B, press cmd-k-2 will just unfold function B, but now all three functions will be unfolded (hence pushing away the cursor from viewable area, a.k.a viewport jumping wild issue)

deathaxe commented 1 year ago

... is it possile to keep cursor always in view after (un)folding?

I can't tell what's possible, just a (power) user not a dev.

The main reason for caret "jumping" around is, ST selecting regions unfolded via key bindings (see #5797). I also find it rather noisy and confusing, but this has been the default for ages accoring to the devs.

But that's probalby a different issue not related with how multiple folded regions in a single line could be unfolded.

... but now all three functions will be unfolded ...

Yes, this behavior has changed. Only selected regions being unfolded/folded was a bug according to devs.

ST now folds all regions by desired level, except the one(s) a caret is within.

coodoo commented 1 year ago

Only selected regions being unfolded/folded was a bug according to devs.

Sigh, if only there is a flag in the configuration file to restore this bug/feature, thanks for making things a bit clear @deathaxe...🥹

@BenjaminSchaaf could you please consider making this happen? (maybe by simply cherry picking from old codebase will do the trick?) 🙏

deathaxe commented 1 year ago

ST4145+ provides a setting to enforce old folding behavior.

    // The style of code folding to use
    // - "auto": Use whatever the default is for the syntax in use
    // - "force_indentation": Always use indentation-based code folding
    // - "scope_only": Only allow syntax-based code folding
    "fold_style": "auto",