From 3c4e235d6704a37830ef80404c06e66f0b66e938 Mon Sep 17 00:00:00 2001 From: Kirill Bulatov Date: Fri, 10 Apr 2026 15:34:50 +0300 Subject: [PATCH] Add settings and disable mouse wheel zoom by default (#53622) Follow-up of https://github.com/zed-industries/zed/pull/53452 Release Notes: - N/A --- assets/settings/default.json | 3 ++ crates/editor/src/editor_settings.rs | 2 + crates/editor/src/element.rs | 5 ++- crates/settings/src/vscode_import.rs | 1 + crates/settings_content/src/editor.rs | 5 +++ crates/settings_ui/src/page_data.rs | 15 ++++++- crates/zed/src/zed.rs | 60 +++++++++++++++++++++++++++ docs/src/reference/all-settings.md | 10 +++++ 8 files changed, 99 insertions(+), 2 deletions(-) diff --git a/assets/settings/default.json b/assets/settings/default.json index 799a34d6a6f4dea367cc2c5cc4ce774ff0ad312e..8e8c93c5088338af63a2daed8c87fe031d500727 100644 --- a/assets/settings/default.json +++ b/assets/settings/default.json @@ -636,6 +636,9 @@ // Scroll sensitivity multiplier. This multiplier is applied // to both the horizontal and vertical delta values while scrolling. "scroll_sensitivity": 1.0, + // Whether to zoom the editor font size with the mouse wheel + // while holding the primary modifier key (Cmd on macOS, Ctrl on other platforms). + "mouse_wheel_zoom": false, // Scroll sensitivity multiplier for fast scrolling. This multiplier is applied // to both the horizontal and vertical delta values while scrolling. Fast scrolling // happens when a user holds the alt or option key while scrolling. diff --git a/crates/editor/src/editor_settings.rs b/crates/editor/src/editor_settings.rs index e4a20476419578ff646952c84b399e2333f0a411..67b56a161f4d92985339d725b553c4baeec05bca 100644 --- a/crates/editor/src/editor_settings.rs +++ b/crates/editor/src/editor_settings.rs @@ -33,6 +33,7 @@ pub struct EditorSettings { pub autoscroll_on_clicks: bool, pub horizontal_scroll_margin: f32, pub scroll_sensitivity: f32, + pub mouse_wheel_zoom: bool, pub fast_scroll_sensitivity: f32, pub sticky_scroll: StickyScroll, pub relative_line_numbers: RelativeLineNumbers, @@ -251,6 +252,7 @@ impl Settings for EditorSettings { autoscroll_on_clicks: editor.autoscroll_on_clicks.unwrap(), horizontal_scroll_margin: editor.horizontal_scroll_margin.unwrap(), scroll_sensitivity: editor.scroll_sensitivity.unwrap(), + mouse_wheel_zoom: editor.mouse_wheel_zoom.unwrap(), fast_scroll_sensitivity: editor.fast_scroll_sensitivity.unwrap(), sticky_scroll: StickyScroll { enabled: sticky_scroll.enabled.unwrap(), diff --git a/crates/editor/src/element.rs b/crates/editor/src/element.rs index 24b9606a83a5bcf2a675e3632f4bc2bad41aa591..fa6b9d30b5b7123e8775ba1d8b65a79461e26ca1 100644 --- a/crates/editor/src/element.rs +++ b/crates/editor/src/element.rs @@ -7675,7 +7675,10 @@ impl EditorElement { if phase == DispatchPhase::Bubble && hitbox.should_handle_scroll(window) { delta = delta.coalesce(event.delta); - if event.modifiers.secondary() && editor.read(cx).enable_mouse_wheel_zoom { + if event.modifiers.secondary() + && editor.read(cx).enable_mouse_wheel_zoom + && EditorSettings::get_global(cx).mouse_wheel_zoom + { let delta_y = match event.delta { ScrollDelta::Pixels(pixels) => pixels.y.into(), ScrollDelta::Lines(lines) => lines.y, diff --git a/crates/settings/src/vscode_import.rs b/crates/settings/src/vscode_import.rs index 5ebf0ba6abd1749ef13b9d8fcd26ac8caa608e51..042b3a7c71c77d8aaa02cec559a943608ee87859 100644 --- a/crates/settings/src/vscode_import.rs +++ b/crates/settings/src/vscode_import.rs @@ -286,6 +286,7 @@ impl VsCodeSettings { }), rounded_selection: self.read_bool("editor.roundedSelection"), scroll_beyond_last_line: None, + mouse_wheel_zoom: self.read_bool("editor.mouseWheelZoom"), scroll_sensitivity: self.read_f32("editor.mouseWheelScrollSensitivity"), scrollbar: self.scrollbar_content(), search: self.search_content(), diff --git a/crates/settings_content/src/editor.rs b/crates/settings_content/src/editor.rs index b37192882694f999a5e7f3180e5a7899a8732393..00a0549d6b8b1ded71069a5ece36ded5d1a69d0e 100644 --- a/crates/settings_content/src/editor.rs +++ b/crates/settings_content/src/editor.rs @@ -89,6 +89,11 @@ pub struct EditorSettingsContent { /// Default: 1.0 #[serde(serialize_with = "crate::serialize_optional_f32_with_two_decimal_places")] pub scroll_sensitivity: Option, + /// Whether to zoom the editor font size with the mouse wheel + /// while holding the primary modifier key (Cmd on macOS, Ctrl on other platforms). + /// + /// Default: false + pub mouse_wheel_zoom: Option, /// Scroll sensitivity multiplier for fast scrolling. This multiplier is applied /// to both the horizontal and vertical delta values while scrolling. Fast scrolling /// happens when a user holds the alt or option key while scrolling. diff --git a/crates/settings_ui/src/page_data.rs b/crates/settings_ui/src/page_data.rs index 1bab4984a1515627ef26042fa7937a328877df0a..cef65431a459126ac14054dee5bc5ffe68e2419c 100644 --- a/crates/settings_ui/src/page_data.rs +++ b/crates/settings_ui/src/page_data.rs @@ -1571,7 +1571,7 @@ fn editor_page() -> SettingsPage { ] } - fn scrolling_section() -> [SettingsPageItem; 8] { + fn scrolling_section() -> [SettingsPageItem; 9] { [ SettingsPageItem::SectionHeader("Scrolling"), SettingsPageItem::SettingItem(SettingItem { @@ -1632,6 +1632,19 @@ fn editor_page() -> SettingsPage { metadata: None, files: USER, }), + SettingsPageItem::SettingItem(SettingItem { + title: "Mouse Wheel Zoom", + description: "Whether to zoom the editor font size with the mouse wheel while holding the primary modifier key.", + field: Box::new(SettingField { + json_path: Some("mouse_wheel_zoom"), + pick: |settings_content| settings_content.editor.mouse_wheel_zoom.as_ref(), + write: |settings_content, value| { + settings_content.editor.mouse_wheel_zoom = value; + }, + }), + metadata: None, + files: USER, + }), SettingsPageItem::SettingItem(SettingItem { title: "Fast Scroll Sensitivity", description: "Fast scroll sensitivity multiplier for both horizontal and vertical scrolling.", diff --git a/crates/zed/src/zed.rs b/crates/zed/src/zed.rs index e3cb1b90d46ed8f758ef0334f82fd07b34c93ea9..63e86a0b7c7980f6591dc248a4313577e8d46bea 100644 --- a/crates/zed/src/zed.rs +++ b/crates/zed/src/zed.rs @@ -4144,6 +4144,7 @@ mod tests { window.draw(cx).clear(); }); + // mouse_wheel_zoom is disabled by default — zoom should not work. let initial_font_size = cx.update(|_, cx| ThemeSettings::get_global(cx).buffer_font_size(cx).as_f32()); @@ -4154,6 +4155,34 @@ mod tests { ..Default::default() }); + let font_size_after_disabled_zoom = + cx.update(|_, cx| ThemeSettings::get_global(cx).buffer_font_size(cx).as_f32()); + + assert_eq!( + initial_font_size, font_size_after_disabled_zoom, + "Editor buffer font-size should not change when mouse_wheel_zoom is disabled" + ); + + // Enable mouse_wheel_zoom and verify zoom works. + cx.update(|_, cx| { + SettingsStore::update_global(cx, |store, cx| { + store.update_user_settings(cx, |settings| { + settings.editor.mouse_wheel_zoom = Some(true); + }); + }); + }); + + cx.update(|window, cx| { + window.draw(cx).clear(); + }); + + cx.simulate_event(gpui::ScrollWheelEvent { + position: mouse_position, + delta: gpui::ScrollDelta::Pixels(point(px(0.), px(1.))), + modifiers: event_modifiers, + ..Default::default() + }); + let increased_font_size = cx.update(|_, cx| ThemeSettings::get_global(cx).buffer_font_size(cx).as_f32()); @@ -4180,6 +4209,37 @@ mod tests { decreased_font_size < increased_font_size, "Editor buffer font-size should have decreased from scroll-zoom" ); + + // Disable mouse_wheel_zoom again and verify zoom stops working. + cx.update(|_, cx| { + SettingsStore::update_global(cx, |store, cx| { + store.update_user_settings(cx, |settings| { + settings.editor.mouse_wheel_zoom = Some(false); + }); + }); + }); + + let font_size_before = + cx.update(|_, cx| ThemeSettings::get_global(cx).buffer_font_size(cx).as_f32()); + + cx.update(|window, cx| { + window.draw(cx).clear(); + }); + + cx.simulate_event(gpui::ScrollWheelEvent { + position: mouse_position, + delta: gpui::ScrollDelta::Pixels(point(px(0.), px(1.))), + modifiers: event_modifiers, + ..Default::default() + }); + + let font_size_after = + cx.update(|_, cx| ThemeSettings::get_global(cx).buffer_font_size(cx).as_f32()); + + assert_eq!( + font_size_before, font_size_after, + "Editor buffer font-size should not change when mouse_wheel_zoom is re-disabled" + ); } #[gpui::test] diff --git a/docs/src/reference/all-settings.md b/docs/src/reference/all-settings.md index cb731de2e11888393ab00aef32b0722765a1ede7..b2b5a76a3a21411b1444268c592e24186ad29797 100644 --- a/docs/src/reference/all-settings.md +++ b/docs/src/reference/all-settings.md @@ -3396,6 +3396,16 @@ List of strings containing any combination of: Positive `float` values +### Mouse Wheel Zoom + +- Description: Whether to zoom the editor font size with the mouse wheel while holding the primary modifier key (Cmd on macOS, Ctrl on other platforms). +- Setting: `mouse_wheel_zoom` +- Default: `false` + +**Options** + +`boolean` values + ### Fast Scroll Sensitivity - Description: Scroll sensitivity multiplier for fast scrolling. This multiplier is applied to both the horizontal and vertical delta values while scrolling. Fast scrolling happens when a user holds the alt or option key while scrolling.