zed icon indicating copy to clipboard operation
zed copied to clipboard

One-lined fold

Open rosingrind opened this issue 2 years ago • 3 comments

Check for existing issues

  • [X] Completed

Describe the feature

Pardon my toxic rant, idk why but I'm overflown with hatred when I click "fold" and see the {... on one line and dangling } on the other line. Zed is definitely a fresh breath and looks very promising, but I'm very frustrated when these kinds of projects do pick up bad habits from the very beginning.

I don't know who started this ugliness parade, but as far as I remember, vscode brought this up to masses. Now they have at least 3 big and easy to find issues for "same line folding", and an entire plugin for this. I know this may be too opinionated here, but I'm definitely not alone.

Imagine a situation: you use a formatter like rustfmt on your code with empty code blocks:

fn foo() {
    let something = 123;
    if something == 2 {} // TODO
    todo!()
}

fn bar() {             }

fn main() {


}

And you get this:

fn foo() {
    let something = 123;
    if something == 2 {
    } // TODO
    todo!()
}

fn bar() {
}

fn main() {
}

Every formatter either do fn main() {} by default, or add an option to leave closing bracket on second line for older code formatting conventions. Again, I may be biased but I believe that leaving closing pair on second line is not fine and looks annoying.

Just fold to 1 (one) line, not 2 (two). Is it so hard to do?

More than that, you already can do this, look up an attached screenshot from your own project:

If applicable, add mockups / screenshots to help present your vision of the feature

image

rosingrind avatar Sep 22 '23 15:09 rosingrind

Absolutely, one hundred percent, fully and totally agree with @rosingrind. Upvote, thumbs up and whatever is needed to draw more attention to this issue. To anyone looking for a code editor that can fold to a single line, well tough luck. Brackets, Atom are both discontinued, VSCode can only do this using a (quite buggy) third party plugin, and JetBrains Fleet preview is quite picky when it comes to folding (cannot fold multiline comments in any way, cannot fold function arguments, but can fold function body to a single line).

I understand that this is a complex issue (eg. folding Python vs folding JavaScript are quite different, folding if-elseif-else is tricky and so on) but it is also an essential tool when working on massive files with a ton of definitions. This is why I tested this code editor in the first place, to finally have an editor that can properly fold.

If there is anything I can help to implement this feature (testing, debugging, documenting, anything) I am happy to help, just please make a code editor that can fold properly.

bencemeszaros avatar Jan 26 '24 11:01 bencemeszaros

Folding is not working as expected as it does in other editors.

Consider this example when I press on line 297

image

It only folds a small piece of code when expected to fold full body of function

image
  • also when I reopen file it doesn't remember folded sections

7flash avatar Feb 01 '24 23:02 7flash

Remembering folds per file would be amazing

thelegendtubaguy avatar Apr 23 '24 02:04 thelegendtubaguy