From c1b3111c15f7170c295420be88df439430cf408f Mon Sep 17 00:00:00 2001 From: "gcp-cherry-pick-bot[bot]" <98988430+gcp-cherry-pick-bot[bot]@users.noreply.github.com> Date: Wed, 9 Jul 2025 20:25:03 -0600 Subject: [PATCH] vim: Fix panic when scrolling beyond last line (cherry-pick #34172) (#34174) Cherry-picked vim: Fix panic when scrolling beyond last line (#34172) cc @dinocosta Release Notes: - (preview only) vim: Fix panic when scrolling down at end of file Co-authored-by: Conrad Irwin --- crates/vim/src/normal/scroll.rs | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/crates/vim/src/normal/scroll.rs b/crates/vim/src/normal/scroll.rs index 47b9fe92fd92eee83c01a5ca0041e67d912d7b4f..e2ae74b52bc6a417abb5827c06d20efe8c926597 100644 --- a/crates/vim/src/normal/scroll.rs +++ b/crates/vim/src/normal/scroll.rs @@ -230,7 +230,11 @@ fn scroll_editor( // column position, or the right-most column in the current // line, seeing as the cursor might be in a short line, in which // case we don't want to go past its last column. - let max_row_column = map.line_len(new_row); + let max_row_column = if new_row <= map.max_point().row() { + map.line_len(new_row) + } else { + 0 + }; let max_column = match min_column + visible_column_count as u32 { max_column if max_column >= max_row_column => max_row_column, max_column => max_column,