diff --git a/crates/terminal/src/terminal.rs b/crates/terminal/src/terminal.rs index 0b38352a54..5472148dad 100644 --- a/crates/terminal/src/terminal.rs +++ b/crates/terminal/src/terminal.rs @@ -1523,14 +1523,11 @@ impl Terminal { // Doesn't make sense to scroll the alt screen if !self.last_content.mode.contains(TermMode::ALT_SCREEN) { - let scroll_delta = match self.drag_line_delta(e, region) { + let scroll_lines = match self.drag_line_delta(e, region) { Some(value) => value, None => return, }; - let scroll_lines = - (scroll_delta / self.last_content.terminal_bounds.line_height) as i32; - self.events .push_back(InternalEvent::Scroll(AlacScroll::Delta(scroll_lines))); } @@ -1539,18 +1536,21 @@ impl Terminal { } } - fn drag_line_delta(&self, e: &MouseMoveEvent, region: Bounds) -> Option { - //TODO: Why do these need to be doubled? Probably the same problem that the IME has - let top = region.origin.y + (self.last_content.terminal_bounds.line_height * 2.); - let bottom = region.bottom_left().y - (self.last_content.terminal_bounds.line_height * 2.); - let scroll_delta = if e.position.y < top { - (top - e.position.y).pow(1.1) + fn drag_line_delta(&self, e: &MouseMoveEvent, region: Bounds) -> Option { + let top = region.origin.y; + let bottom = region.bottom_left().y; + + let scroll_lines = if e.position.y < top { + let scroll_delta = (top - e.position.y).pow(1.1); + (scroll_delta / self.last_content.terminal_bounds.line_height).ceil() as i32 } else if e.position.y > bottom { - -((e.position.y - bottom).pow(1.1)) + let scroll_delta = -((e.position.y - bottom).pow(1.1)); + (scroll_delta / self.last_content.terminal_bounds.line_height).floor() as i32 } else { - return None; //Nothing to do + return None; }; - Some(scroll_delta) + + Some(scroll_lines) } pub fn mouse_down(&mut self, e: &MouseDownEvent, _cx: &mut Context) {