Skip to content

Commit

Permalink
popup: bugfix: reset the position to the cursor when outside the view…
Browse files Browse the repository at this point in the history
…port

while resizing, if the position is outside the view, then the program
panics. check the position and reset it to the cursor position

Signed-off-by: Ben Fekih, Hichem <[email protected]>
  • Loading branch information
karthago1 committed Apr 19, 2024
1 parent 3577335 commit 3ce8fac
Showing 1 changed file with 14 additions and 3 deletions.
17 changes: 14 additions & 3 deletions helix-term/src/ui/popup.rs
Original file line number Diff line number Diff line change
Expand Up @@ -98,9 +98,20 @@ impl<T: Component> Popup<T> {
/// Calculate the position where the popup should be rendered and return the coordinates of the
/// top left corner.
pub fn get_rel_position(&mut self, viewport: Rect, editor: &Editor) -> (u16, u16) {
let position = self
.position
.get_or_insert_with(|| editor.cursor().0.unwrap_or_default());
let position = if let Some(position) = self.position {
// check if the position is still inside the viewport
if position.row as u16 >= viewport.y
&& (position.row as u16) < (viewport.y + viewport.height)
&& position.col as u16 >= viewport.x
&& (position.col as u16) < (viewport.x + viewport.width)
{
position
} else {
editor.cursor().0.unwrap_or_default()
}
} else {
editor.cursor().0.unwrap_or_default()
};

let (width, height) = self.size;

Expand Down

0 comments on commit 3ce8fac

Please sign in to comment.