Add allow_rewrap setting to control editor::Rewrap behavior for a given language (#25173)

This PR adds a new `allow_rewrap` setting to control how
`editor::Rewrap` behaves for a given language.

This is a language setting, so it can either be configured globally or
within the context of an individual language.

For example:

```json
{
  "allow_rewrap": "in_selections",
  "languages": {
    "Typst": {
      "allow_rewrap": "anywhere"
    }
  }
}
```

There are three different values:

- `in_comment`: Only perform rewrapping within comments.
- `in_selections`: Only perform rewrapping within the current
selection(s).
- `anywhere`: Allow rewrapping anywhere.

The global default is `in_comment`, as it is the most conservative
option and allows rewrapping comments without risking breaking other
syntax.

The `Markdown` and `Plain Text` languages default to `anywhere`, which
mirrors the previous behavior for those language that was hard-coded
into the rewrap implementation.

This setting does not have any effect in Vim mode, as Vim mode already
allowed rewrapping anywhere.

Closes https://github.com/zed-industries/zed/issues/24242.

Release Notes:

- Added an `allow_rewrap` setting to control the `editor::Rewrap`
behavior for a given language.
This commit is contained in:
Marshall Bowers
2025-02-19 16:37:39 +00:00
committed by GitHub
parent 1ce8a51712
commit d17c6b392e
4 changed files with 79 additions and 14 deletions
+18 -1
View File
@@ -4321,7 +4321,24 @@ fn test_transpose(cx: &mut TestAppContext) {
#[gpui::test]
async fn test_rewrap(cx: &mut TestAppContext) {
init_test(cx, |_| {});
init_test(cx, |settings| {
settings.languages.extend([
(
"Markdown".into(),
LanguageSettingsContent {
allow_rewrap: Some(language_settings::RewrapBehavior::Anywhere),
..Default::default()
},
),
(
"Plain Text".into(),
LanguageSettingsContent {
allow_rewrap: Some(language_settings::RewrapBehavior::Anywhere),
..Default::default()
},
),
])
});
let mut cx = EditorTestContext::new(cx).await;