From d72d426bfb46439a82fc195c9df148dcfd7be45c Mon Sep 17 00:00:00 2001 From: "Ben Fekih, Hichem" Date: Sat, 6 Apr 2024 22:38:21 +0200 Subject: [PATCH] bugfix: cannot scroll until the end inside a popup 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 --- helix-term/src/ui/popup.rs | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/helix-term/src/ui/popup.rs b/helix-term/src/ui/popup.rs index 4f379b4a1d5b..124b4402fdb1 100644 --- a/helix-term/src/ui/popup.rs +++ b/helix-term/src/ui/popup.rs @@ -283,16 +283,20 @@ impl Component for Popup { (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