Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions assets/settings/default.json
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
2 changes: 2 additions & 0 deletions crates/editor/src/editor_settings.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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(),
Expand Down
5 changes: 4 additions & 1 deletion crates/editor/src/element.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
1 change: 1 addition & 0 deletions crates/settings/src/vscode_import.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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(),
Expand Down
5 changes: 5 additions & 0 deletions crates/settings_content/src/editor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
15 changes: 14 additions & 1 deletion crates/settings_ui/src/page_data.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1571,7 +1571,7 @@ fn editor_page() -> SettingsPage {
]
}

fn scrolling_section() -> [SettingsPageItem; 8] {
fn scrolling_section() -> [SettingsPageItem; 9] {
[
SettingsPageItem::SectionHeader("Scrolling"),
SettingsPageItem::SettingItem(SettingItem {
Expand Down Expand Up @@ -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.",
Expand Down
60 changes: 60 additions & 0 deletions crates/zed/src/zed.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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());

Expand All @@ -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());

Expand All @@ -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]
Expand Down
10 changes: 10 additions & 0 deletions docs/src/reference/all-settings.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
Loading