From c83d007138587d832c5ce3a13c8cb99913c016be Mon Sep 17 00:00:00 2001 From: Kirill Bulatov Date: Thu, 26 Sep 2024 23:43:58 +0300 Subject: [PATCH] Remove non-wrapping settings from the language configuration (#18412) Closes https://github.com/zed-industries/zed/issues/17736 Those are limited with 1024 symbols before wrapping still, and were introduced for git diff deleted hunks display. Instead of confusing people with actually wrapping, restores behavior that was before https://github.com/zed-industries/zed/pull/11080 Release Notes: - Removed confusing soft wrap option behavior ([#17736]https://github.com/zed-industries/zed/issues/17736) --- assets/settings/default.json | 7 +++---- crates/editor/src/editor.rs | 24 +++++++++++++++++------- crates/editor/src/element.rs | 6 ++---- crates/language/src/language_settings.rs | 9 +++++---- docs/src/configuring-zed.md | 6 +++--- 5 files changed, 30 insertions(+), 22 deletions(-) diff --git a/assets/settings/default.json b/assets/settings/default.json index cf0de6a5e7f9aa5f907b765e2836a73f2e100bc9..b3be17ad2cedcf2116deffe1b8fdceec707fdc33 100644 --- a/assets/settings/default.json +++ b/assets/settings/default.json @@ -535,17 +535,16 @@ // How to soft-wrap long lines of text. // Possible values: // - // 1. Do not soft wrap. - // "soft_wrap": "none", // 2. Prefer a single line generally, unless an overly long line is encountered. - // "soft_wrap": "prefer_line", + // "soft_wrap": "none", + // "soft_wrap": "prefer_line", // (deprecated, same as "none") // 3. Soft wrap lines that overflow the editor. // "soft_wrap": "editor_width", // 4. Soft wrap lines at the preferred line length. // "soft_wrap": "preferred_line_length", // 5. Soft wrap lines at the preferred line length or the editor width (whichever is smaller). // "soft_wrap": "bounded", - "soft_wrap": "prefer_line", + "soft_wrap": "none", // The column at which to soft-wrap lines, for buffers where soft-wrap // is enabled. "preferred_line_length": 80, diff --git a/crates/editor/src/editor.rs b/crates/editor/src/editor.rs index 54d23a8219d4f47a4f622b5d0acae3bc22c0049a..b7f825df9eec606296b49eb64ed3cc2aa6908ff7 100644 --- a/crates/editor/src/editor.rs +++ b/crates/editor/src/editor.rs @@ -376,12 +376,20 @@ pub enum EditorMode { Full, } -#[derive(Clone, Debug)] +#[derive(Copy, Clone, Debug)] pub enum SoftWrap { + /// Prefer not to wrap at all. + /// + /// Note: this is currently internal, as actually limited by [`crate::MAX_LINE_LEN`] until it wraps. + /// The mode is used inside git diff hunks, where it's seems currently more useful to not wrap as much as possible. + GitDiff, + /// Prefer a single line generally, unless an overly long line is encountered. None, - PreferLine, + /// Soft wrap lines that exceed the editor width. EditorWidth, + /// Soft wrap lines at the preferred line length. Column(u32), + /// Soft wrap line at the preferred line length or the editor width (whichever is smaller). Bounded(u32), } @@ -1837,7 +1845,7 @@ impl Editor { let blink_manager = cx.new_model(|cx| BlinkManager::new(CURSOR_BLINK_INTERVAL, cx)); let soft_wrap_mode_override = matches!(mode, EditorMode::SingleLine { .. }) - .then(|| language_settings::SoftWrap::PreferLine); + .then(|| language_settings::SoftWrap::None); let mut project_subscriptions = Vec::new(); if mode == EditorMode::Full { @@ -10898,8 +10906,9 @@ impl Editor { let settings = self.buffer.read(cx).settings_at(0, cx); let mode = self.soft_wrap_mode_override.unwrap_or(settings.soft_wrap); match mode { - language_settings::SoftWrap::None => SoftWrap::None, - language_settings::SoftWrap::PreferLine => SoftWrap::PreferLine, + language_settings::SoftWrap::PreferLine | language_settings::SoftWrap::None => { + SoftWrap::None + } language_settings::SoftWrap::EditorWidth => SoftWrap::EditorWidth, language_settings::SoftWrap::PreferredLineLength => { SoftWrap::Column(settings.preferred_line_length) @@ -10947,9 +10956,10 @@ impl Editor { self.soft_wrap_mode_override.take(); } else { let soft_wrap = match self.soft_wrap_mode(cx) { - SoftWrap::None | SoftWrap::PreferLine => language_settings::SoftWrap::EditorWidth, + SoftWrap::GitDiff => return, + SoftWrap::None => language_settings::SoftWrap::EditorWidth, SoftWrap::EditorWidth | SoftWrap::Column(_) | SoftWrap::Bounded(_) => { - language_settings::SoftWrap::PreferLine + language_settings::SoftWrap::None } }; self.soft_wrap_mode_override = Some(soft_wrap); diff --git a/crates/editor/src/element.rs b/crates/editor/src/element.rs index 6f30062d47ec770b1406d42329d941453d18df20..bad16b225f3298be30d9ca99b26a1e2940245cdb 100644 --- a/crates/editor/src/element.rs +++ b/crates/editor/src/element.rs @@ -4994,10 +4994,8 @@ impl Element for EditorElement { snapshot } else { let wrap_width = match editor.soft_wrap_mode(cx) { - SoftWrap::None => None, - SoftWrap::PreferLine => { - Some((MAX_LINE_LEN / 2) as f32 * em_advance) - } + SoftWrap::GitDiff => None, + SoftWrap::None => Some((MAX_LINE_LEN / 2) as f32 * em_advance), SoftWrap::EditorWidth => Some(editor_width), SoftWrap::Column(column) => Some(column as f32 * em_advance), SoftWrap::Bounded(column) => { diff --git a/crates/language/src/language_settings.rs b/crates/language/src/language_settings.rs index f830c5f25c308cbe5a22145b185f5c5c2a8ffd4d..2f1a7be2bf492d73baab8f30aa20847edeb85719 100644 --- a/crates/language/src/language_settings.rs +++ b/crates/language/src/language_settings.rs @@ -379,15 +379,16 @@ pub struct FeaturesContent { #[derive(Copy, Clone, Debug, Serialize, Deserialize, PartialEq, Eq, JsonSchema)] #[serde(rename_all = "snake_case")] pub enum SoftWrap { - /// Do not soft wrap. + /// Prefer a single line generally, unless an overly long line is encountered. None, + /// Deprecated: use None instead. Left to avoid breakin existing users' configs. /// Prefer a single line generally, unless an overly long line is encountered. PreferLine, - /// Soft wrap lines that exceed the editor width + /// Soft wrap lines that exceed the editor width. EditorWidth, - /// Soft wrap lines at the preferred line length + /// Soft wrap lines at the preferred line length. PreferredLineLength, - /// Soft wrap line at the preferred line length or the editor width (whichever is smaller) + /// Soft wrap line at the preferred line length or the editor width (whichever is smaller). Bounded, } diff --git a/docs/src/configuring-zed.md b/docs/src/configuring-zed.md index 7837044a60a669d19b911a5fd16187c77434e2fa..18d66708ad7fc886a544b047ce9e3d4219b74ac3 100644 --- a/docs/src/configuring-zed.md +++ b/docs/src/configuring-zed.md @@ -1357,12 +1357,12 @@ Or to set a `socks5` proxy: - Description: Whether or not to automatically wrap lines of text to fit editor / preferred width. - Setting: `soft_wrap` -- Default: `prefer_line` +- Default: `none` **Options** -1. `none` to stop the soft-wrapping -2. `prefer_line` to avoid wrapping generally, unless the line is too long +1. `none` to avoid wrapping generally, unless the line is too long +2. `prefer_line` (deprecated, same as `none`) 3. `editor_width` to wrap lines that overflow the editor width 4. `preferred_line_length` to wrap lines that overflow `preferred_line_length` config value