Code at the speed of thought – Zed is a high-performance, multiplayer code editor from the creators of Atom and Tree-sitter.
Restrict mouse wheel zoom for certain editors (#53598)
Kirill Bulatov2635ef55c6df
diff --git a/crates/agent_ui/src/agent_diff.rs b/crates/agent_ui/src/agent_diff.rsindex 7b70740dd1a..567595143a4 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.rsindex 412778e054c..32fe52480e2 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.rsindex f2beb719cc7..ce74b7f78cd 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.rsindex 0f59441ab27..3b93439b623 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.rsindex 65bc949b2b6..c541257b6d2 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.rsindex c9c2688f80e..09fc8ece435 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<bool>,use_relative_line_numbers: Option<bool>,show_git_diff_gutter: Option<bool>,@@ -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.rsindex 12a79fa6695..24b9606a83a 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.rsindex 7ec2d7ba830..135c8f22116 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);editordiff --git a/crates/keymap_editor/src/keymap_editor.rs b/crates/keymap_editor/src/keymap_editor.rsindex ee9f6a11c2b..c4833620cf4 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.rsindex ba70e50f8cb..cb8f1d51103 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.rsindex cda63ab9c8a..7b8261d27b6 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 = cxdiff --git a/crates/theme_settings/src/theme_settings.rs b/crates/theme_settings/src/theme_settings.rsindex f5bc96ba02a..39ffe832746 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.rsindex 3d4ada8a1b9..e3cb1b90d46 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);}}})