From c42303304296ffec635825ca9b45395f64784ca6 Mon Sep 17 00:00:00 2001 From: Antonio Scandurra Date: Thu, 27 May 2021 18:23:32 +0200 Subject: [PATCH] Fix panic in `autoindent_for_rows` caused by overshooting row range --- zed/src/editor/buffer/mod.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/zed/src/editor/buffer/mod.rs b/zed/src/editor/buffer/mod.rs index 9396cb59ba5aba71f67cb36d735e2e082bb2d10f..82fe359689068a31c6f733c20e8fd3f8fcb71bba 100644 --- a/zed/src/editor/buffer/mod.rs +++ b/zed/src/editor/buffer/mod.rs @@ -740,7 +740,7 @@ impl Buffer { let node_end_row = capture.node.end_position().row; let start_ix = (node_start_row + 1).saturating_sub(start_row); let end_ix = (node_end_row + 1).saturating_sub(start_row); - for ix in start_ix..end_ix { + for ix in start_ix..cmp::min(end_ix, indents.len()) { indents[ix] += language.config.indent; } } @@ -751,7 +751,7 @@ impl Buffer { let node_end_row = capture.node.end_position().row; let start_ix = node_start_row.saturating_sub(start_row); let end_ix = (node_end_row + 1).saturating_sub(start_row); - for ix in start_ix..end_ix { + for ix in start_ix..cmp::min(end_ix, indents.len()) { indents[ix] = indents[ix].saturating_sub(language.config.indent); } }