Fix unscaled scrolling when using an imprecise mouse wheel

This commit is contained in:
Mikayla Maki 2022-11-16 10:44:13 -08:00
parent 3c53fcdb43
commit 8e6c5dbc3b
8 changed files with 83 additions and 28 deletions

View file

@ -97,7 +97,7 @@ impl MouseButton {
}
fn from_scroll(e: &ScrollWheelEvent) -> Self {
if e.delta.y() > 0. {
if e.delta.raw().y() > 0. {
MouseButton::ScrollUp
} else {
MouseButton::ScrollDown

View file

@ -1144,7 +1144,7 @@ impl Terminal {
fn determine_scroll_lines(&mut self, e: &MouseScrollWheel, mouse_mode: bool) -> Option<i32> {
let scroll_multiplier = if mouse_mode { 1. } else { SCROLL_MULTIPLIER };
let line_height = self.last_content.size.line_height;
match e.phase {
/* Reset scroll state on started */
Some(gpui::TouchPhase::Started) => {
@ -1153,11 +1153,11 @@ impl Terminal {
}
/* Calculate the appropriate scroll lines */
Some(gpui::TouchPhase::Moved) => {
let old_offset = (self.scroll_px / self.last_content.size.line_height) as i32;
let old_offset = (self.scroll_px / line_height) as i32;
self.scroll_px += e.delta.y() * scroll_multiplier;
self.scroll_px += e.delta.pixel_delta(line_height).y() * scroll_multiplier;
let new_offset = (self.scroll_px / self.last_content.size.line_height) as i32;
let new_offset = (self.scroll_px / line_height) as i32;
// Whenever we hit the edges, reset our stored scroll to 0
// so we can respond to changes in direction quickly
@ -1167,7 +1167,7 @@ impl Terminal {
}
/* Fall back to delta / line_height */
None => Some(
((e.delta.y() * scroll_multiplier) / self.last_content.size.line_height) as i32,
((e.delta.pixel_delta(line_height).y() * scroll_multiplier) / line_height) as i32,
),
_ => None,
}