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 20, 2024
1 parent a889df7 commit 5c11cf1
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 @@ -135,9 +135,20 @@ impl<T: Component> Popup<T> {
let width = child_size.0.min(viewport.width);
let height = child_size.1.min(viewport.height.saturating_sub(2)); // add some spacing in the viewport

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()
};

// if there's a orientation preference, use that
// if we're on the top part of the screen, do below
Expand Down

0 comments on commit 5c11cf1

Please sign in to comment.