Remove Scroll internal action

This commit is contained in:
Antonio Scandurra 2023-04-28 16:43:31 +02:00
parent 3409ee1785
commit f65e64829e
2 changed files with 17 additions and 27 deletions

View file

@ -13,9 +13,7 @@ use crate::{
link_go_to_definition::{ link_go_to_definition::{
go_to_fetched_definition, go_to_fetched_type_definition, update_go_to_definition_link, go_to_fetched_definition, go_to_fetched_type_definition, update_go_to_definition_link,
}, },
mouse_context_menu, mouse_context_menu, EditorStyle, GutterHover, UnfoldAt,
scroll::actions::Scroll,
EditorStyle, GutterHover, UnfoldAt,
}; };
use clock::ReplicaId; use clock::ReplicaId;
use collections::{BTreeMap, HashMap}; use collections::{BTreeMap, HashMap};
@ -194,11 +192,12 @@ impl EditorElement {
}) })
.on_scroll({ .on_scroll({
let position_map = position_map.clone(); let position_map = position_map.clone();
move |e, _, cx| { move |event, editor, cx| {
if !Self::scroll( if !Self::scroll(
e.position, editor,
*e.delta.raw(), event.position,
e.delta.precise(), *event.delta.raw(),
event.delta.precise(),
&position_map, &position_map,
bounds, bounds,
cx, cx,
@ -430,6 +429,7 @@ impl EditorElement {
} }
fn scroll( fn scroll(
editor: &mut Editor,
position: Vector2F, position: Vector2F,
mut delta: Vector2F, mut delta: Vector2F,
precise: bool, precise: bool,
@ -457,11 +457,7 @@ impl EditorElement {
let x = (scroll_position.x() * max_glyph_width - delta.x()) / max_glyph_width; 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 y = (scroll_position.y() * line_height - delta.y()) / line_height;
let scroll_position = vec2f(x, y).clamp(Vector2F::zero(), position_map.scroll_max); let scroll_position = vec2f(x, y).clamp(Vector2F::zero(), position_map.scroll_max);
editor.scroll(scroll_position, axis, cx);
cx.dispatch_action(Scroll {
scroll_position,
axis,
});
true true
} }

View file

@ -1,6 +1,4 @@
use gpui::{ use gpui::{actions, geometry::vector::Vector2F, AppContext, Axis, ViewContext};
actions, geometry::vector::Vector2F, impl_internal_actions, AppContext, Axis, ViewContext,
};
use language::Bias; use language::Bias;
use crate::{Editor, EditorMode}; use crate::{Editor, EditorMode};
@ -23,17 +21,8 @@ actions!(
] ]
); );
#[derive(Clone, PartialEq)]
pub struct Scroll {
pub scroll_position: Vector2F,
pub axis: Option<Axis>,
}
impl_internal_actions!(editor, [Scroll]);
pub fn init(cx: &mut AppContext) { pub fn init(cx: &mut AppContext) {
cx.add_action(Editor::next_screen); cx.add_action(Editor::next_screen);
cx.add_action(Editor::scroll);
cx.add_action(Editor::scroll_cursor_top); cx.add_action(Editor::scroll_cursor_top);
cx.add_action(Editor::scroll_cursor_center); cx.add_action(Editor::scroll_cursor_center);
cx.add_action(Editor::scroll_cursor_bottom); cx.add_action(Editor::scroll_cursor_bottom);
@ -75,9 +64,14 @@ impl Editor {
Some(()) Some(())
} }
fn scroll(&mut self, action: &Scroll, cx: &mut ViewContext<Self>) { pub fn scroll(
self.scroll_manager.update_ongoing_scroll(action.axis); &mut self,
self.set_scroll_position(action.scroll_position, cx); scroll_position: Vector2F,
axis: Option<Axis>,
cx: &mut ViewContext<Self>,
) {
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<Editor>) { fn scroll_cursor_top(editor: &mut Editor, _: &ScrollCursorTop, cx: &mut ViewContext<Editor>) {