Fix panic when buffer larger than terminal width
commit1b67fae9f4eabf0899dda441971b8a338cb45a15
authorRowan Herbert <rlherbert.dev@gmail.com>
dateWed 2 Jun 2021, 16:30 (5 years ago)
parent7761c88
helix-view/src/view.rs+3−2
@@ -143,8 +143,9 @@ impl View {
143143 }
144144 }
145145
146− let row = line - self.first_line as usize;
147− let col = col - self.first_col as usize;
146+ // It is possible for underflow to occur if the buffer length is larger than the terminal width.
147+ let row = line.saturating_sub(self.first_line);
148+ let col = col.saturating_sub(self.first_col);
148149
149150 Some(Position::new(row, col))
150151 }