From 2635ef55c6df198cc11324fdb1bbff690411465b Mon Sep 17 00:00:00 2001 From: Kirill Bulatov Date: Fri, 10 Apr 2026 12:20:38 +0300 Subject: [PATCH] Restrict mouse wheel zoom for certain editors (#53598) Follow-up of https://github.com/zed-industries/zed/pull/53452 * disables mouse wheel zooming in agent, debugger, keymap editor, dev inspector and repl-related editors * adjusts the code to call for theme changes directly instead of sending the events, so that agent following does not capture the events and changes its font size Release Notes: - N/A --- crates/agent_ui/src/agent_diff.rs | 1 + .../src/conversation_view/thread_view.rs | 1 + crates/agent_ui/src/inline_assistant.rs | 1 + crates/agent_ui/src/message_editor.rs | 1 + .../src/session/running/console.rs | 1 + crates/editor/src/editor.rs | 13 +++++++++++-- crates/editor/src/element.rs | 17 +++++------------ crates/inspector_ui/src/div_inspector.rs | 1 + crates/keymap_editor/src/keymap_editor.rs | 1 + crates/repl/src/notebook/cell.rs | 3 +++ crates/theme_settings/src/settings.rs | 3 ++- crates/theme_settings/src/theme_settings.rs | 19 ++++++++++++++++--- crates/zed/src/zed.rs | 4 ++-- 13 files changed, 46 insertions(+), 20 deletions(-) diff --git a/crates/agent_ui/src/agent_diff.rs b/crates/agent_ui/src/agent_diff.rs index 7b70740dd1ac462614a9d08d9e48d7d13ac2ed32..567595143a41e71a25237e3b1bdcf2301880bccb 100644 --- a/crates/agent_ui/src/agent_diff.rs +++ b/crates/agent_ui/src/agent_diff.rs @@ -98,6 +98,7 @@ impl AgentDiffPane { editor .set_render_diff_hunk_controls(diff_hunk_controls(&thread, workspace.clone()), cx); editor.register_addon(AgentDiffAddon); + editor.disable_mouse_wheel_zoom(); editor }); diff --git a/crates/agent_ui/src/conversation_view/thread_view.rs b/crates/agent_ui/src/conversation_view/thread_view.rs index 412778e054cab1596b2e9555a9cd4a12c3edb6ec..32fe52480e2c347cc482b2296a107ee8731fb672 100644 --- a/crates/agent_ui/src/conversation_view/thread_view.rs +++ b/crates/agent_ui/src/conversation_view/thread_view.rs @@ -5170,6 +5170,7 @@ impl ThreadView { let mut editor = Editor::for_multibuffer(buffer, Some(project.clone()), window, cx); editor.set_breadcrumb_header(thread_title); + editor.disable_mouse_wheel_zoom(); editor })), None, diff --git a/crates/agent_ui/src/inline_assistant.rs b/crates/agent_ui/src/inline_assistant.rs index f2beb719cc7e5638cfc36f339419bda405a8e773..ce74b7f78cda0ea14a79593f83e5666795f80e5e 100644 --- a/crates/agent_ui/src/inline_assistant.rs +++ b/crates/agent_ui/src/inline_assistant.rs @@ -1483,6 +1483,7 @@ impl InlineAssistant { editor.set_show_wrap_guides(false, cx); editor.set_show_gutter(false, cx); editor.set_offset_content(false, cx); + editor.disable_mouse_wheel_zoom(); editor.scroll_manager.set_forbid_vertical_scroll(true); editor.set_read_only(true); editor.set_show_edit_predictions(Some(false), window, cx); diff --git a/crates/agent_ui/src/message_editor.rs b/crates/agent_ui/src/message_editor.rs index 0f59441ab27b5074a710c46a683e72d003a8d5d7..3b93439b62305f63596abcaebe562e7b3f2a65f3 100644 --- a/crates/agent_ui/src/message_editor.rs +++ b/crates/agent_ui/src/message_editor.rs @@ -422,6 +422,7 @@ impl MessageEditor { editor.set_show_indent_guides(false, cx); editor.set_show_completions_on_input(Some(true)); editor.set_soft_wrap(); + editor.disable_mouse_wheel_zoom(); editor.set_use_modal_editing(true); editor.set_context_menu_options(ContextMenuOptions { min_entries_visible: 12, diff --git a/crates/debugger_ui/src/session/running/console.rs b/crates/debugger_ui/src/session/running/console.rs index 65bc949b2b6ddb1a707abf2e001ffde151fb70b8..c541257b6d219b56a611f8a3711da287109ef48d 100644 --- a/crates/debugger_ui/src/session/running/console.rs +++ b/crates/debugger_ui/src/session/running/console.rs @@ -84,6 +84,7 @@ impl Console { editor.set_show_indent_guides(false, cx); editor.set_show_edit_predictions(Some(false), window, cx); editor.set_use_modal_editing(false); + editor.disable_mouse_wheel_zoom(); editor.set_soft_wrap_mode(language::language_settings::SoftWrap::EditorWidth, cx); editor }); diff --git a/crates/editor/src/editor.rs b/crates/editor/src/editor.rs index c9c2688f80edc14e879ae50adb654d3cf2c9ae8a..09fc8ece435c8aff22bbf380709669282bd28dcd 100644 --- a/crates/editor/src/editor.rs +++ b/crates/editor/src/editor.rs @@ -1183,6 +1183,7 @@ pub struct Editor { delegate_open_excerpts: bool, enable_lsp_data: bool, enable_runnables: bool, + enable_mouse_wheel_zoom: bool, show_line_numbers: Option, use_relative_line_numbers: Option, show_git_diff_gutter: Option, @@ -1972,6 +1973,9 @@ impl Editor { clone.read_only = self.read_only; clone.buffers_with_disabled_indent_guides = self.buffers_with_disabled_indent_guides.clone(); + clone.enable_mouse_wheel_zoom = self.enable_mouse_wheel_zoom; + clone.enable_lsp_data = self.enable_lsp_data; + clone.enable_runnables = self.enable_runnables; clone } @@ -2419,8 +2423,9 @@ impl Editor { delegate_expand_excerpts: false, delegate_stage_and_restore: false, delegate_open_excerpts: false, - enable_lsp_data: true, - enable_runnables: true, + enable_lsp_data: full_mode, + enable_runnables: full_mode, + enable_mouse_wheel_zoom: full_mode, show_git_diff_gutter: None, show_code_actions: None, show_runnables: None, @@ -26082,6 +26087,10 @@ impl Editor { self.enable_runnables = false; } + pub fn disable_mouse_wheel_zoom(&mut self) { + self.enable_mouse_wheel_zoom = false; + } + fn update_data_on_scroll(&mut self, window: &mut Window, cx: &mut Context<'_, Self>) { self.register_visible_buffers(cx); self.colorize_brackets(false, cx); diff --git a/crates/editor/src/element.rs b/crates/editor/src/element.rs index 12a79fa6695ddff8371fa1b648056f43bec0cb98..24b9606a83a5bcf2a675e3632f4bc2bad41aa591 100644 --- a/crates/editor/src/element.rs +++ b/crates/editor/src/element.rs @@ -7673,22 +7673,18 @@ impl EditorElement { move |event: &ScrollWheelEvent, phase, window, cx| { if phase == DispatchPhase::Bubble && hitbox.should_handle_scroll(window) { - if event.modifiers.secondary() { + delta = delta.coalesce(event.delta); + + if event.modifiers.secondary() && editor.read(cx).enable_mouse_wheel_zoom { let delta_y = match event.delta { ScrollDelta::Pixels(pixels) => pixels.y.into(), ScrollDelta::Lines(lines) => lines.y, }; if delta_y > 0.0 { - window.dispatch_action( - Box::new(zed_actions::IncreaseBufferFontSize { persist: false }), - cx, - ); + theme_settings::increase_buffer_font_size(cx); } else if delta_y < 0.0 { - window.dispatch_action( - Box::new(zed_actions::DecreaseBufferFontSize { persist: false }), - cx, - ); + theme_settings::decrease_buffer_font_size(cx); } cx.stop_propagation(); @@ -7701,10 +7697,7 @@ impl EditorElement { } }; - delta = delta.coalesce(event.delta); editor.update(cx, |editor, cx| { - let position_map: &PositionMap = &position_map; - let line_height = position_map.line_height; let glyph_width = position_map.em_layout_width; let (delta, axis) = match delta { diff --git a/crates/inspector_ui/src/div_inspector.rs b/crates/inspector_ui/src/div_inspector.rs index 7ec2d7ba8303e899331d3f38642a9a51f4c14d4c..135c8f22116498fbc0db43c88928a365e5607ce5 100644 --- a/crates/inspector_ui/src/div_inspector.rs +++ b/crates/inspector_ui/src/div_inspector.rs @@ -498,6 +498,7 @@ impl DivInspector { editor.set_show_breakpoints(false, cx); editor.set_show_git_diff_gutter(false, cx); editor.set_show_runnables(false, cx); + editor.disable_mouse_wheel_zoom(); editor.set_show_edit_predictions(Some(false), window, cx); editor.set_minimap_visibility(MinimapVisibility::Disabled, window, cx); editor diff --git a/crates/keymap_editor/src/keymap_editor.rs b/crates/keymap_editor/src/keymap_editor.rs index ee9f6a11c2b51f7993b17c01352cfb97b535049a..c4833620cf4ec0a6dc965aa9e23c2690a44773fd 100644 --- a/crates/keymap_editor/src/keymap_editor.rs +++ b/crates/keymap_editor/src/keymap_editor.rs @@ -3318,6 +3318,7 @@ impl ActionArgumentsEditor { window, cx, ); + editor.disable_mouse_wheel_zoom(); editor.set_searchable(false); editor.disable_scrollbars_and_minimap(window, cx); editor.set_show_edit_predictions(Some(false), window, cx); diff --git a/crates/repl/src/notebook/cell.rs b/crates/repl/src/notebook/cell.rs index ba70e50f8cbccc32bef5de5c1864a3d8db46aa89..cb8f1d51103fca83cb92718e51a80c42f1e6be62 100644 --- a/crates/repl/src/notebook/cell.rs +++ b/crates/repl/src/notebook/cell.rs @@ -378,6 +378,7 @@ impl MarkdownCell { editor.set_show_gutter(false, cx); editor.set_text_style_refinement(refinement); editor.set_use_modal_editing(true); + editor.disable_mouse_wheel_zoom(); editor }); @@ -641,6 +642,7 @@ impl CodeCell { ..Default::default() }; + editor.disable_mouse_wheel_zoom(); editor.set_show_gutter(false, cx); editor.set_text_style_refinement(refinement); editor.set_use_modal_editing(true); @@ -718,6 +720,7 @@ impl CodeCell { ..Default::default() }; + editor.disable_mouse_wheel_zoom(); editor.set_text(source.clone(), window, cx); editor.set_show_gutter(false, cx); editor.set_text_style_refinement(refinement); diff --git a/crates/theme_settings/src/settings.rs b/crates/theme_settings/src/settings.rs index cda63ab9c8aa10d0f006f3bf371aab6491dff6de..7b8261d27b6ef1c04677d74f868f85e6356daba7 100644 --- a/crates/theme_settings/src/settings.rs +++ b/crates/theme_settings/src/settings.rs @@ -490,7 +490,8 @@ pub fn adjusted_font_size(size: Pixels, cx: &App) -> Pixels { clamp_font_size(adjusted_font_size) } -/// Adjusts the buffer font size. +/// Adjusts the buffer font size, without persisting the result in the settings. +/// This will be effective until the app is restarted. pub fn adjust_buffer_font_size(cx: &mut App, f: impl FnOnce(Pixels) -> Pixels) { let buffer_font_size = ThemeSettings::get_global(cx).buffer_font_size; let adjusted_size = cx diff --git a/crates/theme_settings/src/theme_settings.rs b/crates/theme_settings/src/theme_settings.rs index f5bc96ba02a63088b6311055899b39de65ea9de2..39ffe8327460431ede9c2d1c9a012d0de503fdb2 100644 --- a/crates/theme_settings/src/theme_settings.rs +++ b/crates/theme_settings/src/theme_settings.rs @@ -12,7 +12,7 @@ use std::sync::Arc; use ::settings::{IntoGpui, Settings, SettingsStore}; use anyhow::{Context as _, Result}; -use gpui::{App, Font, HighlightStyle, Pixels, Refineable}; +use gpui::{App, Font, HighlightStyle, Pixels, Refineable, px}; use gpui_util::ResultExt; use theme::{ AccentColors, Appearance, AppearanceContent, DEFAULT_DARK_THEME, DEFAULT_ICON_THEME_NAME, @@ -26,11 +26,12 @@ pub use crate::schema::{ ThemeColorsContent, ThemeContent, ThemeFamilyContent, ThemeStyleContent, WindowBackgroundContent, status_colors_refinement, syntax_overrides, theme_colors_refinement, }; +use crate::settings::adjust_buffer_font_size; pub use crate::settings::{ AgentFontSize, BufferLineHeight, FontFamilyName, IconThemeName, IconThemeSelection, ThemeAppearanceMode, ThemeName, ThemeSelection, ThemeSettings, adjust_agent_buffer_font_size, - adjust_agent_ui_font_size, adjust_buffer_font_size, adjust_ui_font_size, adjusted_font_size, - appearance_to_mode, clamp_font_size, default_theme, observe_buffer_font_size_adjustment, + adjust_agent_ui_font_size, adjust_ui_font_size, adjusted_font_size, appearance_to_mode, + clamp_font_size, default_theme, observe_buffer_font_size_adjustment, reset_agent_buffer_font_size, reset_agent_ui_font_size, reset_buffer_font_size, reset_ui_font_size, set_icon_theme, set_mode, set_theme, setup_ui_font, }; @@ -410,3 +411,15 @@ pub fn merge_accent_colors( accent_colors.0 = Arc::from(colors); } } + +/// Increases the buffer font size by 1 pixel, without persisting the result in the settings. +/// This will be effective until the app is restarted. +pub fn increase_buffer_font_size(cx: &mut App) { + adjust_buffer_font_size(cx, |size| size + px(1.0)); +} + +/// Decreases the buffer font size by 1 pixel, without persisting the result in the settings. +/// This will be effective until the app is restarted. +pub fn decrease_buffer_font_size(cx: &mut App) { + adjust_buffer_font_size(cx, |size| size - px(1.0)); +} diff --git a/crates/zed/src/zed.rs b/crates/zed/src/zed.rs index 3d4ada8a1b90020090eb74a8a6ea752fa7a44ab3..e3cb1b90d46ed8f758ef0334f82fd07b34c93ea9 100644 --- a/crates/zed/src/zed.rs +++ b/crates/zed/src/zed.rs @@ -928,7 +928,7 @@ fn register_actions( .insert(f32::from(theme_settings::clamp_font_size(buffer_font_size)).into()); }); } else { - theme_settings::adjust_buffer_font_size(cx, |size| size + px(1.0)); + theme_settings::increase_buffer_font_size(cx); } } }) @@ -945,7 +945,7 @@ fn register_actions( .insert(f32::from(theme_settings::clamp_font_size(buffer_font_size)).into()); }); } else { - theme_settings::adjust_buffer_font_size(cx, |size| size - px(1.0)); + theme_settings::decrease_buffer_font_size(cx); } } })