Skip to content

Commit

Permalink
EditView: Prevent overflow error with no available space
Browse files Browse the repository at this point in the history
  • Loading branch information
gyscos committed Oct 5, 2016
1 parent 8fded82 commit bb62452
Showing 1 changed file with 5 additions and 0 deletions.
5 changes: 5 additions & 0 deletions src/views/edit_view.rs
Original file line number Diff line number Diff line change
Expand Up @@ -229,6 +229,10 @@ impl EditView {
.map(|g| g.width())
.next()
.unwrap_or(1);
if c_len > self.last_length {
// Weird - no available space?
return;
}
// Now, we have to fit self.content[..self.cursor]
// into self.last_length - c_len.
let available = self.last_length - c_len;
Expand All @@ -239,6 +243,7 @@ impl EditView {
simple_suffix_length(&self.content[self.offset..self.cursor],
available);
self.offset = self.cursor - suffix_length;
// Make sure the cursor is in view
assert!(self.cursor >= self.offset);

}
Expand Down

0 comments on commit bb62452

Please sign in to comment.