From ab33b6a1ade63f8c2418060767b15ee80e58fece Mon Sep 17 00:00:00 2001 From: "gcp-cherry-pick-bot[bot]" <98988430+gcp-cherry-pick-bot[bot]@users.noreply.github.com> Date: Mon, 13 May 2024 13:51:44 -0600 Subject: [PATCH] Fix panic when accepting completions (cherry-pick #11762) (#11763) Cherry-picked Fix panic when accepting completions (#11762) Release Notes: - Fixed a panic caused by missing bounds check in completion handler Co-authored-by: Conrad Irwin --- crates/editor/src/editor.rs | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/crates/editor/src/editor.rs b/crates/editor/src/editor.rs index ba7a40e3b49c3c2adee3e0698a407d61328880eb..79667774ea3115eb94ea302197f15671afefcd38 100644 --- a/crates/editor/src/editor.rs +++ b/crates/editor/src/editor.rs @@ -4639,12 +4639,11 @@ impl Editor { delta += snippet.text.len() as isize - insertion_range.len() as isize; - let start = snapshot.anchor_before( - (insertion_start + tabstop_range.start) as usize, - ); - let end = snapshot - .anchor_after((insertion_start + tabstop_range.end) as usize); - start..end + let start = ((insertion_start + tabstop_range.start) as usize) + .min(snapshot.len()); + let end = ((insertion_start + tabstop_range.end) as usize) + .min(snapshot.len()); + snapshot.anchor_before(start)..snapshot.anchor_after(end) }) }) .collect::>();