zed-industries / zed

Code at the speed of thought – Zed is a high-performance, multiplayer code editor from the creators of Atom and Tree-sitter.
https://zed.dev
Other
39.96k stars 2.08k forks source link

Add command to toggle hard wrap/unwrap paragraphs #4588

Open Yevgnen opened 11 months ago

Yevgnen commented 11 months ago

Check for existing issues

Describe the feature

The command should work for current block/graph of texts based on "preferred_line_length". For example

The English Wikipedia is the primary[a] English-language edition of Wikipedia, an online encyclopedia. It was created by Jimmy Wales and Larry Sanger on January 15, 2001, as Wikipedia's first edition.

English Wikipedia is hosted alongside other language editions by the Wikimedia Foundation, an American non-profit organization. Its content is written independently of other editions[1] in various varieties of English, aiming to stay consistent within articles. Its internal newspaper is The Signpost.

English Wikipedia is the most-read version of Wikipedia[2] and has the most articles of any edition, at 6,689,175 as of July 2023.[3] It contains 10.9% of articles in all Wikipedias,[3] although it lacks millions of articles found in other editions.[1] The edition's one-billionth edit was made on January 13, 2021.[4]

If the cursor in the second block of text, toggling hard wrapping should turn the text into

The English Wikipedia is the primary[a] English-language edition of Wikipedia, an online encyclopedia. It was created by Jimmy Wales and Larry Sanger on January 15, 2001, as Wikipedia's first edition.

English Wikipedia is hosted alongside other language editions by the
Wikimedia Foundation, an American non-profit organization. Its content
is written independently of other editions[1] in various varieties of
English, aiming to stay consistent within articles. Its internal
newspaper is The Signpost.

English Wikipedia is the most-read version of Wikipedia[2] and has the most articles of any edition, at 6,689,175 as of July 2023.[3] It contains 10.9% of articles in all Wikipedias,[3] although it lacks millions of articles found in other editions.[1] The edition's one-billionth edit was made on January 13, 2021.[4]

toggling again should go back to the original text.

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

No response

mcginty commented 10 months ago

To add on to this request (one of the things I feel like I use a lot in vim and miss here), it'd be nice to have this bound to gq and behave similarly to it in general, that is: if this command is called on a comment, it will automatically add the proper comment leaders and indentation to make it multiline post-formatting.

gq also does "reflow" to make the text pretty based on a preferred line width, some examples with a Rust formatting, "preferred_line_length": 30:

Simple case

Before

// This is a one line long comment that will trail off the right side of the screen.

After gq

// This is a one line long
// comment that will trail off
// the right side of the
// screen.

More advanced case

Before

// This
// is
// a distubing
// comment that is spaced
// super
// weird.
//
// We don't like those comments. They hurt my eyes.

After gq

// This is a disturbing comment
// that is spaced super weird.
//
// We don't like those
// comments. They hurt my
// eyes.
failable commented 10 months ago

Emacs user totally agree with all these use cases!