Skip to content

Commit

Permalink
Fix scrolling to the end within a popup (helix-editor#10181)
Browse files Browse the repository at this point in the history
when the available height for the popup is low/small, then it is not
possible to scroll until the end

Signed-off-by: Ben Fekih, Hichem <[email protected]>
  • Loading branch information
karthago1 authored and mtoohey31 committed Jun 2, 2024
1 parent ef6dcf2 commit a0f63d5
Showing 1 changed file with 8 additions and 4 deletions.
12 changes: 8 additions & 4 deletions helix-term/src/ui/popup.rs
Original file line number Diff line number Diff line change
Expand Up @@ -283,16 +283,20 @@ impl<T: Component> Component for Popup<T> {
(height + self.margin.height()).min(max_height),
);

// re-clamp scroll offset
let max_offset = self.child_size.1.saturating_sub(self.size.1);
self.scroll = self.scroll.min(max_offset as usize);

Some(self.size)
}

fn render(&mut self, viewport: Rect, surface: &mut Surface, cx: &mut Context) {
let area = self.area(viewport, cx.editor);
self.area = area;

// required_size() calculates the popup size without taking account of self.position
// so we need to correct the popup height to correctly calculate the scroll
self.size.1 = area.height;

// re-clamp scroll offset
let max_offset = self.child_size.1.saturating_sub(self.size.1);
self.scroll = self.scroll.min(max_offset as usize);
cx.scroll = Some(self.scroll);

// clear area
Expand Down

0 comments on commit a0f63d5

Please sign in to comment.