Repository: alacritty/alacritty
File: alacritty/src/input/mod.rs (Rust)

Code before:
                }
            },
        }
    }

    fn scroll_terminal(&mut self, new_scroll_x_px: f64, new_scroll_y_px: f64, multiplier: f64) {
        const MOUSE_WHEEL_UP: u8 = 64;
        const MOUSE_WHEEL_DOWN: u8 = 65;
        const MOUSE_WHEEL_LEFT: u8 = 66;
        const MOUSE_WHEEL_RIGHT: u8 = 67;

        let width = f64::from(self.ctx.size_info().cell_width());
        let height = f64::from(self.ctx.size_info().cell_height());

        let multiplier = if self.ctx.mouse_mode() { 1. } else { multiplier };

        self.ctx.mouse_mut().accumulated_scroll.x += new_scroll_x_px * multiplier;
        self.ctx.mouse_mut().accumulated_scroll.y += new_scroll_y_px * multiplier;

        let lines = (self.ctx.mouse().accumulated_scroll.y / height).abs() as usize;
        let columns = (self.ctx.mouse().accumulated_scroll.x / width).abs() as usize;

        let scroll_up = new_scroll_y_px > 0.;
        let event = if scroll_up { MouseEvent::WheelUp } else { MouseEvent::WheelDown };

        if lines != 0 && self.process_mouse_bindings(event) {
            // Repeat for remaining number of lines.
            for _ in 1..lines {
                self.process_mouse_bindings(event);
            }
        } else if self.ctx.mouse_mode() {
            let code = if scroll_up { MOUSE_WHEEL_UP } else { MOUSE_WHEEL_DOWN };
            for _ in 0..lines {
                self.mouse_report(code, ElementState::Pressed);
            }

            let code = if new_scroll_x_px > 0. { MOUSE_WHEEL_LEFT } else { MOUSE_WHEEL_RIGHT };
            for _ in 0..columns {
                self.mouse_report(code, ElementState::Pressed);
            }
        } else if self
            .ctx
            .terminal()
            .mode()
            .contains(TermMode::ALT_SCREEN | TermMode::ALTERNATE_SCROLL)
            && !self.ctx.modifiers().state().shift_key()
        {
            // The chars here are the same as for the respective arrow keys.
            let line_cmd = if scroll_up { b'A' } else { b'B' };
            let column_cmd = if new_scroll_x_px > 0. { b'D' } else { b'C' };


Review comment (suggestion):
Was contemplating if we should skip all other branches too `if lines != 0`, but that would break with horizontal scrolling I believe. Just wanted to point it out for myself.

Code after:
                }
            },
        }
    }

    fn scroll_terminal(&mut self, new_scroll_x_px: f64, new_scroll_y_px: f64, multiplier: f64) {
        const MOUSE_WHEEL_UP: u8 = 64;
        const MOUSE_WHEEL_DOWN: u8 = 65;
        const MOUSE_WHEEL_LEFT: u8 = 66;
        const MOUSE_WHEEL_RIGHT: u8 = 67;

        let width = f64::from(self.ctx.size_info().cell_width());
        let height = f64::from(self.ctx.size_info().cell_height());

        let multiplier = if self.ctx.mouse_mode() { 1. } else { multiplier };

        self.ctx.mouse_mut().accumulated_scroll.x += new_scroll_x_px * multiplier;
        self.ctx.mouse_mut().accumulated_scroll.y += new_scroll_y_px * multiplier;

        let lines = (self.ctx.mouse().accumulated_scroll.y / height).abs() as usize;
        let columns = (self.ctx.mouse().accumulated_scroll.x / width).abs() as usize;

        let is_scroll_up = new_scroll_y_px > 0.;
        let event = if is_scroll_up { MouseEvent::WheelUp } else { MouseEvent::WheelDown };

        if lines != 0 && self.process_mouse_bindings(event) {
            // Repeat for remaining number of lines.
            for _ in 1..lines {
                self.process_mouse_bindings(event);
            }
        } else if self.ctx.mouse_mode() {
            let code = if is_scroll_up { MOUSE_WHEEL_UP } else { MOUSE_WHEEL_DOWN };
            for _ in 0..lines {
                self.mouse_report(code, ElementState::Pressed);
            }

            let code = if new_scroll_x_px > 0. { MOUSE_WHEEL_LEFT } else { MOUSE_WHEEL_RIGHT };
            for _ in 0..columns {
                self.mouse_report(code, ElementState::Pressed);
            }
        } else if self
            .ctx
            .terminal()
            .mode()
            .contains(TermMode::ALT_SCREEN | TermMode::ALTERNATE_SCROLL)
            && !self.ctx.modifiers().state().shift_key()
        {
            // The chars here are the same as for the respective arrow keys.
            let line_cmd = if is_scroll_up { b'A' } else { b'B' };
            let column_cmd = if new_scroll_x_px > 0. { b'D' } else { b'C' };