From a2aa47aba2f8d1240aa435d8e0708cff57199f0d Mon Sep 17 00:00:00 2001 From: Julia Date: Mon, 22 Jan 2024 18:12:25 -0500 Subject: [PATCH] Avoid overwriting mouse wheel scroll with selection auto-scroll --- crates/editor/src/editor.rs | 10 +++++----- crates/editor/src/element.rs | 3 +-- crates/editor/src/scroll.rs | 22 +++++++++++++++++++++- 3 files changed, 27 insertions(+), 8 deletions(-) diff --git a/crates/editor/src/editor.rs b/crates/editor/src/editor.rs index e378425666c9550e30c18d447d67baf3b0e05c76..4be449f3cdee12fd88aece382920c1bb18f4ea1c 100644 --- a/crates/editor/src/editor.rs +++ b/crates/editor/src/editor.rs @@ -281,7 +281,7 @@ pub enum SelectPhase { Update { position: DisplayPoint, goal_column: u32, - scroll_position: gpui::Point, + scroll_delta: gpui::Point, }, End, } @@ -1928,8 +1928,8 @@ impl Editor { SelectPhase::Update { position, goal_column, - scroll_position, - } => self.update_selection(position, goal_column, scroll_position, cx), + scroll_delta, + } => self.update_selection(position, goal_column, scroll_delta, cx), SelectPhase::End => self.end_selection(cx), } } @@ -2063,7 +2063,7 @@ impl Editor { &mut self, position: DisplayPoint, goal_column: u32, - scroll_position: gpui::Point, + scroll_delta: gpui::Point, cx: &mut ViewContext, ) { let display_map = self.display_map.update(cx, |map, cx| map.snapshot(cx)); @@ -2152,7 +2152,7 @@ impl Editor { return; } - self.set_scroll_position(scroll_position, cx); + self.apply_scroll_delta(scroll_delta, cx); cx.notify(); } diff --git a/crates/editor/src/element.rs b/crates/editor/src/element.rs index eeb8263f30fa1449350bf7872d45866cadadb54f..519e17a5af761a546ea5941cdeb5dd6ed329cf72 100644 --- a/crates/editor/src/element.rs +++ b/crates/editor/src/element.rs @@ -531,8 +531,7 @@ impl EditorElement { SelectPhase::Update { position: point_for_position.previous_valid, goal_column: point_for_position.exact_unclipped.column(), - scroll_position: (position_map.snapshot.scroll_position() + scroll_delta) - .clamp(&gpui::Point::default(), &position_map.scroll_max), + scroll_delta, }, cx, ); diff --git a/crates/editor/src/scroll.rs b/crates/editor/src/scroll.rs index f68004109e8889600c08b91ffe1edc5cc54ddee1..3f68b7d2d991439b9548fa298ebbfd18daeeeb9d 100644 --- a/crates/editor/src/scroll.rs +++ b/crates/editor/src/scroll.rs @@ -327,6 +327,16 @@ impl Editor { } } + pub fn apply_scroll_delta( + &mut self, + scroll_delta: gpui::Point, + cx: &mut ViewContext, + ) { + let display_map = self.display_map.update(cx, |map, cx| map.snapshot(cx)); + let position = self.scroll_manager.anchor.scroll_position(&display_map) + scroll_delta; + self.set_scroll_position_taking_display_map(position, true, false, display_map, cx); + } + pub fn set_scroll_position( &mut self, scroll_position: gpui::Point, @@ -343,12 +353,22 @@ impl Editor { cx: &mut ViewContext, ) { let map = self.display_map.update(cx, |map, cx| map.snapshot(cx)); + self.set_scroll_position_taking_display_map(scroll_position, local, autoscroll, map, cx); + } + fn set_scroll_position_taking_display_map( + &mut self, + scroll_position: gpui::Point, + local: bool, + autoscroll: bool, + display_map: DisplaySnapshot, + cx: &mut ViewContext, + ) { hide_hover(self, cx); let workspace_id = self.workspace.as_ref().map(|workspace| workspace.1); self.scroll_manager.set_scroll_position( scroll_position, - &map, + &display_map, local, autoscroll, workspace_id,