diff --git a/crates/editor/src/editor.rs b/crates/editor/src/editor.rs index 0acfef3086..49612a59f9 100644 --- a/crates/editor/src/editor.rs +++ b/crates/editor/src/editor.rs @@ -1675,11 +1675,14 @@ impl Editor { .log_err(); } else { self.buffer.update(cx, |buffer, cx| { - buffer.edit_with_autoindent( - [completion.old_range.clone()], - &completion.new_text, - cx, - ); + let snapshot = buffer.read(cx); + let old_range = completion.old_range.to_offset(&snapshot); + if old_range.len() != completion.new_text.len() + || !snapshot.contains_str_at(old_range.start, &completion.new_text) + { + drop(snapshot); + buffer.edit_with_autoindent([old_range], &completion.new_text, cx); + } }); } diff --git a/crates/language/src/buffer.rs b/crates/language/src/buffer.rs index 00dee0a57c..f5ea67f5fe 100644 --- a/crates/language/src/buffer.rs +++ b/crates/language/src/buffer.rs @@ -1888,7 +1888,9 @@ impl Buffer { .await?; if let Some(additional_edits) = resolved_completion.additional_text_edits { this.update(&mut cx, |this, cx| { - this.avoid_grouping_next_transaction(); + if !push_to_history { + this.avoid_grouping_next_transaction(); + } this.start_transaction(); let edit_ids = this.apply_lsp_edits(additional_edits, cx); if let Some(transaction_id) = this.end_transaction(cx) {