From 3f4d4af080f210f1048cdbc8e98ad6df0524b533 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jo=C3=A3o=20Marcos?= Date: Tue, 15 Apr 2025 20:37:37 -0300 Subject: [PATCH] fix slicing crash in `do_completion` (#28820) Release Notes: - N/A --- crates/editor/src/editor.rs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/crates/editor/src/editor.rs b/crates/editor/src/editor.rs index 58f6e549a4..c587a61620 100644 --- a/crates/editor/src/editor.rs +++ b/crates/editor/src/editor.rs @@ -4737,8 +4737,8 @@ impl Editor { let lookahead = replace_range .end .saturating_sub(newest_anchor.end.text_anchor.to_offset(buffer)); - let prefix = &old_text[..old_text.len() - lookahead]; - let suffix = &old_text[lookbehind..]; + let prefix = &old_text[..old_text.len().saturating_sub(lookahead)]; + let suffix = &old_text[lookbehind.min(old_text.len())..]; let selections = self.selections.all::(cx); let mut edits = Vec::new(); @@ -4753,7 +4753,7 @@ impl Editor { // if prefix is present, don't duplicate it if snapshot.contains_str_at(range.start.saturating_sub(lookbehind), prefix) { - text = &new_text[lookbehind..]; + text = &new_text[lookbehind.min(new_text.len())..]; // if suffix is also present, mimic the newest cursor and replace it if selection.id != newest_anchor.id