From 1b67fae9f4eabf0899dda441971b8a338cb45a15 Mon Sep 17 00:00:00 2001 From: Rowan Herbert Date: Wed, 2 Jun 2021 16:30:40 -0700 Subject: [PATCH] Fix panic when buffer larger than terminal width --- helix-view/src/view.rs | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/helix-view/src/view.rs b/helix-view/src/view.rs index f82de90e7..b7bfaa17e 100644 --- a/helix-view/src/view.rs +++ b/helix-view/src/view.rs @@ -143,8 +143,9 @@ impl View { } } - let row = line - self.first_line as usize; - let col = col - self.first_col as usize; + // It is possible for underflow to occur if the buffer length is larger than the terminal width. + let row = line.saturating_sub(self.first_line); + let col = col.saturating_sub(self.first_col); Some(Position::new(row, col)) }