diff --git a/crates/editor/src/element.rs b/crates/editor/src/element.rs index e3a160175d..11d1ce8cae 100644 --- a/crates/editor/src/element.rs +++ b/crates/editor/src/element.rs @@ -13,9 +13,7 @@ use crate::{ link_go_to_definition::{ go_to_fetched_definition, go_to_fetched_type_definition, update_go_to_definition_link, }, - mouse_context_menu, - scroll::actions::Scroll, - EditorStyle, GutterHover, UnfoldAt, + mouse_context_menu, EditorStyle, GutterHover, UnfoldAt, }; use clock::ReplicaId; use collections::{BTreeMap, HashMap}; @@ -194,11 +192,12 @@ impl EditorElement { }) .on_scroll({ let position_map = position_map.clone(); - move |e, _, cx| { + move |event, editor, cx| { if !Self::scroll( - e.position, - *e.delta.raw(), - e.delta.precise(), + editor, + event.position, + *event.delta.raw(), + event.delta.precise(), &position_map, bounds, cx, @@ -430,6 +429,7 @@ impl EditorElement { } fn scroll( + editor: &mut Editor, position: Vector2F, mut delta: Vector2F, precise: bool, @@ -457,11 +457,7 @@ impl EditorElement { let x = (scroll_position.x() * max_glyph_width - delta.x()) / max_glyph_width; let y = (scroll_position.y() * line_height - delta.y()) / line_height; let scroll_position = vec2f(x, y).clamp(Vector2F::zero(), position_map.scroll_max); - - cx.dispatch_action(Scroll { - scroll_position, - axis, - }); + editor.scroll(scroll_position, axis, cx); true } diff --git a/crates/editor/src/scroll/actions.rs b/crates/editor/src/scroll/actions.rs index 3b73a4bcbd..a79b0f2449 100644 --- a/crates/editor/src/scroll/actions.rs +++ b/crates/editor/src/scroll/actions.rs @@ -1,6 +1,4 @@ -use gpui::{ - actions, geometry::vector::Vector2F, impl_internal_actions, AppContext, Axis, ViewContext, -}; +use gpui::{actions, geometry::vector::Vector2F, AppContext, Axis, ViewContext}; use language::Bias; use crate::{Editor, EditorMode}; @@ -23,17 +21,8 @@ actions!( ] ); -#[derive(Clone, PartialEq)] -pub struct Scroll { - pub scroll_position: Vector2F, - pub axis: Option, -} - -impl_internal_actions!(editor, [Scroll]); - pub fn init(cx: &mut AppContext) { cx.add_action(Editor::next_screen); - cx.add_action(Editor::scroll); cx.add_action(Editor::scroll_cursor_top); cx.add_action(Editor::scroll_cursor_center); cx.add_action(Editor::scroll_cursor_bottom); @@ -75,9 +64,14 @@ impl Editor { Some(()) } - fn scroll(&mut self, action: &Scroll, cx: &mut ViewContext) { - self.scroll_manager.update_ongoing_scroll(action.axis); - self.set_scroll_position(action.scroll_position, cx); + pub fn scroll( + &mut self, + scroll_position: Vector2F, + axis: Option, + cx: &mut ViewContext, + ) { + self.scroll_manager.update_ongoing_scroll(axis); + self.set_scroll_position(scroll_position, cx); } fn scroll_cursor_top(editor: &mut Editor, _: &ScrollCursorTop, cx: &mut ViewContext) {