Repository navigation
editor: Smooth scrolling #44827
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
editor: Smooth scrolling #44827
Changes from 68 commits
576c72c
408989c
0afdc8e
a647739
2322376
8efc7f5
a905674
c7c14f8
f6abc30
5b8c5b1
005b280
22e01ee
ce5c212
579f8ef
1e88aa1
bcc7db0
1e0fcbc
6c9895c
1edfb8b
24a8804
273bb98
e4a8213
f9b4cd7
3ae7336
bd178d9
2d9ca6a
92b8786
c46a5f8
95ec7ab
d674eb0
ba0809f
81f59aa
d825191
1e03c97
562b234
4d33ece
354192c
29697e1
ea9c615
b8f89a6
477f1a6
a636a0b
ffdf2f6
0dd32cc
93b5271
03b0191
4c680f5
ee79325
38dd5c6
eaecfe3
2b5e8e8
fb71957
ed676d1
dde4a80
4887c62
08f8c54
f5fdfe8
ddc24db
efa70ff
4665173
ef1ed53
037ef66
2c06a7d
642d169
3c15aa7
efd3b7a
3e8fd59
bfe9e4f
7355d20
0d8fd32
97119a7
b2d2f6a
3addcc6
010562b
5bfe7e6
6f39444
177165a
2f5e431
3cd92f7
6f7c4bf
de5494f
dddcd0e
e78ad40
dd7d7f6
249c69f
9558b63
6461d3b
4640666
af6d534
210df1e
b51d60d
1be94ce
37b2cbe
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -650,6 +650,12 @@ | |
| // to both the horizontal and vertical delta values while scrolling. Fast scrolling | ||
| // happens when a user holds the alt or option key while scrolling. | ||
| "fast_scroll_sensitivity": 4.0, | ||
| "smooth_scroll": { | ||
| // Whether to animate scrolling with a smooth easing effect. | ||
| "enabled": false, | ||
| // Duration of the animation | ||
| "duration": 0.125, | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I am not entirely sure we should make the duration configurable at all - I am sold on having the behavior change based on the input type used, and feel like making the duration configurable might be better to do at a later step if at all. This feels like a case where good defaults might just be more worth than to make this configurable in the first place. The fact that VSCode does not have a setting for this makes me feel like we might not need it as well or at least not in the first place.
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. That makes sense. The main reason I added it initially was that scrolling felt much slower when smooth scrolling was enabled. Later I discovered that increasing the sensitivity fixes that, so it definitely makes sense to remove it. Should be done 😊 |
||
| }, | ||
| "sticky_scroll": { | ||
| // Whether to stick scopes to the top of the editor. | ||
| "enabled": false, | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -230,7 +230,7 @@ use crate::{ | |
| InlineValueCache, | ||
| inlay_hints::{LspInlayHintData, inlay_hint_settings}, | ||
| }, | ||
| scroll::{ScrollOffset, ScrollPixelOffset}, | ||
| scroll::{ScrollAnimation, ScrollOffset, ScrollPixelOffset}, | ||
| selections_collection::resolve_selections_wrapping_blocks, | ||
| semantic_tokens::SemanticTokenState, | ||
| signature_help::{SignatureHelpHiddenBy, SignatureHelpState}, | ||
|
|
@@ -1407,6 +1407,7 @@ pub struct EditorSnapshot { | |
| pub placeholder_display_snapshot: Option<DisplaySnapshot>, | ||
| is_focused: bool, | ||
| scroll_anchor: SharedScrollAnchor, | ||
| pub scroll_animation: Option<ScrollAnimation>, | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is there a good reason for this to be pub?
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Should be done |
||
| ongoing_scroll: OngoingScroll, | ||
| current_line_highlight: CurrentLineHighlight, | ||
| gutter_hovered: bool, | ||
|
|
@@ -3184,6 +3185,7 @@ impl Editor { | |
| .placeholder_display_map | ||
| .as_ref() | ||
| .map(|display_map| display_map.update(cx, |map, cx| map.snapshot(cx))), | ||
| scroll_animation: self.scroll_manager.scroll_animation().copied(), | ||
| ongoing_scroll: self.scroll_manager.ongoing_scroll(), | ||
| is_focused: self.focus_handle.is_focused(window), | ||
| current_line_highlight: self | ||
|
|
@@ -27681,6 +27683,14 @@ impl EditorSnapshot { | |
| self.scroll_anchor.scroll_position(&self.display_snapshot) | ||
| } | ||
|
|
||
| pub fn scroll_target_or_position(&self) -> gpui::Point<ScrollOffset> { | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can we not just have
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We don't need to distinguish them anymore, should be done |
||
| if let Some(animation) = self.scroll_animation { | ||
| animation.target_position | ||
| } else { | ||
| self.scroll_position() | ||
| } | ||
| } | ||
|
|
||
| pub fn gutter_dimensions( | ||
| &self, | ||
| font_id: FontId, | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -29,8 +29,8 @@ use crate::{ | |
| inlay_hint_settings, | ||
| mouse_context_menu::{self, MenuPosition}, | ||
| scroll::{ | ||
| ActiveScrollbarState, Autoscroll, ScrollOffset, ScrollPixelOffset, ScrollbarThumbState, | ||
| scroll_amount::ScrollAmount, | ||
| ActiveScrollbarState, Autoscroll, ScrollBehavior, ScrollOffset, ScrollPixelOffset, | ||
| ScrollbarThumbState, scroll_amount::ScrollAmount, | ||
| }, | ||
| }; | ||
| use buffer_diff::{DiffHunkStatus, DiffHunkStatusKind}; | ||
|
|
@@ -7656,6 +7656,7 @@ impl EditorElement { | |
| editor.update(cx, |editor, cx| { | ||
| let position_map: &PositionMap = &position_map; | ||
|
|
||
| let is_precise = delta.precise(); | ||
| let line_height = position_map.line_height; | ||
| let glyph_width = position_map.em_layout_width; | ||
| let (delta, axis) = match delta { | ||
|
|
@@ -7673,21 +7674,39 @@ impl EditorElement { | |
| }; | ||
|
|
||
| let current_scroll_position = position_map.snapshot.scroll_position(); | ||
| let x = (current_scroll_position.x * ScrollPixelOffset::from(glyph_width) | ||
|
|
||
| let base_scroll_position = if is_precise { | ||
| editor.scroll_manager.cancel_animation(); | ||
| current_scroll_position | ||
| } else { | ||
| position_map | ||
| .snapshot | ||
| .scroll_animation | ||
| .map(|animation| animation.target_position) | ||
| .unwrap_or(current_scroll_position) | ||
| }; | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Could you briefly elaborate on the logic here?
This comment was marked as spam.
Sorry, something went wrong.
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @MrSubidubi I've removed this logic it's not necessary anymore. It was an attempt to understand the scrolling slowness difference between mouse and trackpad. |
||
|
|
||
| let x = (base_scroll_position.x * ScrollPixelOffset::from(glyph_width) | ||
| - ScrollPixelOffset::from(delta.x * scroll_sensitivity)) | ||
| / ScrollPixelOffset::from(glyph_width); | ||
| let y = (current_scroll_position.y * ScrollPixelOffset::from(line_height) | ||
| let y = (base_scroll_position.y * ScrollPixelOffset::from(line_height) | ||
| - ScrollPixelOffset::from(delta.y * scroll_sensitivity)) | ||
| / ScrollPixelOffset::from(line_height); | ||
| let mut scroll_position = | ||
| point(x, y).clamp(&point(0., 0.), &position_map.scroll_max); | ||
| let forbid_vertical_scroll = editor.scroll_manager.forbid_vertical_scroll(); | ||
| if forbid_vertical_scroll { | ||
| scroll_position.y = current_scroll_position.y; | ||
| scroll_position.y = base_scroll_position.y; | ||
| } | ||
|
|
||
| if scroll_position != current_scroll_position { | ||
| editor.scroll(scroll_position, axis, window, cx); | ||
| if scroll_position != base_scroll_position { | ||
| let scroll_behaviour = if is_precise { | ||
| ScrollBehavior::Instant | ||
| } else { | ||
| ScrollBehavior::RequestAnimation | ||
| }; | ||
|
|
||
| editor.scroll(scroll_position, axis, scroll_behaviour, window, cx); | ||
| cx.stop_propagation(); | ||
| } else if y < 0. { | ||
| // Due to clamping, we may fail to detect cases of overscroll to the top; | ||
|
|
@@ -9725,6 +9744,16 @@ impl Element for EditorElement { | |
| ); | ||
| editor.set_visible_column_count(f64::from(editor_width / em_advance)); | ||
|
|
||
| if let Some(animation) = editor.scroll_manager.update_animation() { | ||
| use crate::scroll::ScrollAnimationPhase; | ||
|
|
||
| editor.set_scroll_position(animation.position, window, cx); | ||
|
|
||
| if animation.phase == ScrollAnimationPhase::Intermediate { | ||
| window.request_animation_frame(); | ||
| } | ||
| } | ||
|
|
||
| if matches!( | ||
| editor.mode, | ||
| EditorMode::AutoHeight { .. } | EditorMode::Minimap { .. } | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.