Skip to content

Commit

Permalink
Don't call scrollbar functions if disabled in config
Browse files Browse the repository at this point in the history
This fixes issues in tests, where alacritty is tested without display
and therefore also without scrollbar. Previously it panicked because the
display was unimplemented.
  • Loading branch information
flash-freezing-lava committed Sep 30, 2023
1 parent 27dd4e3 commit 08cf060
Showing 1 changed file with 20 additions and 13 deletions.
33 changes: 20 additions & 13 deletions alacritty/src/input.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ use alacritty_terminal::term::{ClipboardType, Term, TermMode};
use alacritty_terminal::vi_mode::ViMotion;

use crate::clipboard::Clipboard;
use crate::config::ui_config::ScrollbarMode;
use crate::config::{
Action, BindingKey, BindingMode, MouseAction, SearchAction, UiConfig, ViAction,
};
Expand Down Expand Up @@ -626,12 +627,14 @@ impl<T: EventListener, A: ActionContext<T>> Processor<T, A> {

/// Handle left click selection and vi mode cursor movement.
fn on_left_click(&mut self, point: Point) {
let size_info = self.ctx.size_info();
let mouse_x = self.ctx.mouse().x;
let mouse_y = self.ctx.mouse().y;
if self.ctx.display().scrollbar.try_start_drag(size_info, mouse_x, mouse_y) {
return;
};
if self.ctx.config().scrollbar.mode != ScrollbarMode::Never {
let size_info = self.ctx.size_info();
let mouse_x = self.ctx.mouse().x;
let mouse_y = self.ctx.mouse().y;
if self.ctx.display().scrollbar.try_start_drag(size_info, mouse_x, mouse_y) {
return;
};
}

let side = self.ctx.mouse().cell_side;

Expand Down Expand Up @@ -668,7 +671,7 @@ impl<T: EventListener, A: ActionContext<T>> Processor<T, A> {
}

fn on_mouse_release(&mut self, button: MouseButton) {
if self.ctx.display().scrollbar.is_dragging() {
if self.ctx.config().scrollbar.mode != ScrollbarMode::Never && self.ctx.display().scrollbar.is_dragging() {
self.ctx.display().scrollbar.stop_dragging();
// Mouse icon is different, when not scrolling.
let mouse_state = self.cursor_state();
Expand Down Expand Up @@ -834,13 +837,17 @@ impl<T: EventListener, A: ActionContext<T>> Processor<T, A> {
let old_touch_purpose = mem::take(self.ctx.touch_purpose());
let new_touch_purpose = match old_touch_purpose {
TouchPurpose::None => {
let size_info = self.ctx.size_info();
let mouse_x = touch.location.x as usize;
let mouse_y = touch.location.y as usize;
if self.ctx.display().scrollbar.try_start_drag( size_info, mouse_x, mouse_y) {
TouchPurpose::ScrollbarDrag(touch)
} else {
if self.ctx.config().scrollbar.mode == ScrollbarMode::Never {
TouchPurpose::Tap(touch)
} else {
let size_info = self.ctx.size_info();
let mouse_x = touch.location.x as usize;
let mouse_y = touch.location.y as usize;
if self.ctx.display().scrollbar.try_start_drag( size_info, mouse_x, mouse_y) {
TouchPurpose::ScrollbarDrag(touch)
} else {
TouchPurpose::Tap(touch)
}
}
},
TouchPurpose::Tap(start) => TouchPurpose::Zoom(TouchZoom::new((start, touch))),
Expand Down

0 comments on commit 08cf060

Please sign in to comment.