Code at the speed of thought – Zed is a high-performance, multiplayer code editor from the creators of Atom and Tree-sitter.
Add settings and disable mouse wheel zoom by default (#53622)
Kirill Bulatov3c4e235d6704
diff --git a/assets/settings/default.json b/assets/settings/default.jsonindex 799a34d6a6f..8e8c93c5088 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.rsindex e4a20476419..67b56a161f4 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.rsindex 24b9606a83a..fa6b9d30b5b 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.rsindex 5ebf0ba6abd..042b3a7c71c 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.rsindex b3719288269..00a0549d6b8 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<f32>,+ /// 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<bool>,/// 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.rsindex 1bab4984a15..cef65431a45 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.rsindex e3cb1b90d46..63e86a0b7c7 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.mdindex cb731de2e11..b2b5a76a3a2 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.