Skip to content

Commit

Permalink
vim: Fix panic due to overflow when scrolling
Browse files Browse the repository at this point in the history
When setting `"vertical_scroll_margin": 99` or other high values
this can lead to a panic that crashes Zed.

Co-authored-by: Bennet <bennet@zed.dev>
  • Loading branch information
mrnugget and bennetbo committed Aug 9, 2024
1 parent 19d8422 commit 343aef8
Showing 1 changed file with 4 additions and 1 deletion.
5 changes: 4 additions & 1 deletion crates/vim/src/normal/scroll.rs
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,10 @@ fn scroll_editor(
DisplayRow(top.row().0 + vertical_scroll_margin as u32)
};
let max_row = DisplayRow(
top.row().0 + visible_line_count as u32 - vertical_scroll_margin as u32 - 1,
top.row().0
+ (visible_line_count as u32)
.saturating_sub(vertical_scroll_margin as u32)
.saturating_sub(1),
);

let new_head = if head.row() < min_row {
Expand Down

0 comments on commit 343aef8

Please sign in to comment.