Skip to content

Commit

Permalink
Scroll popup contents on mouse scroll event
Browse files Browse the repository at this point in the history
  • Loading branch information
sudormrfbin committed Mar 30, 2024
1 parent 563bc2f commit 4dfa235
Showing 1 changed file with 16 additions and 0 deletions.
16 changes: 16 additions & 0 deletions helix-term/src/ui/popup.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ use tui::{
use helix_core::Position;
use helix_view::{
graphics::{Margin, Rect},
input::{MouseEvent, MouseEventKind},
Editor,
};

Expand Down Expand Up @@ -179,12 +180,27 @@ impl<T: Component> Popup<T> {
// clip to viewport
viewport.intersection(Rect::new(rel_x, rel_y, self.size.0, self.size.1))
}

fn handle_mouse_event(&mut self, event: &MouseEvent) -> EventResult {
return match event.kind {
MouseEventKind::ScrollDown if self.has_scrollbar => {
self.scroll_half_page_down();
EventResult::Consumed(None)
}
MouseEventKind::ScrollUp if self.has_scrollbar => {
self.scroll_half_page_up();
EventResult::Consumed(None)
}
_ => EventResult::Ignored(None),
};
}
}

impl<T: Component> Component for Popup<T> {
fn handle_event(&mut self, event: &Event, cx: &mut Context) -> EventResult {
let key = match event {
Event::Key(event) => *event,
Event::Mouse(event) => return self.handle_mouse_event(event),
Event::Resize(_, _) => {
// TODO: calculate inner area, call component's handle_event with that area
return EventResult::Ignored(None);
Expand Down

0 comments on commit 4dfa235

Please sign in to comment.