Don't apply completion's edit when it wouldn't change the buffer
Co-Authored-By: Nathan Sobo <nathan@zed.dev>
This commit is contained in:
parent
924eb622ae
commit
8d7815456c
2 changed files with 11 additions and 6 deletions
|
@ -1675,11 +1675,14 @@ impl Editor {
|
||||||
.log_err();
|
.log_err();
|
||||||
} else {
|
} else {
|
||||||
self.buffer.update(cx, |buffer, cx| {
|
self.buffer.update(cx, |buffer, cx| {
|
||||||
buffer.edit_with_autoindent(
|
let snapshot = buffer.read(cx);
|
||||||
[completion.old_range.clone()],
|
let old_range = completion.old_range.to_offset(&snapshot);
|
||||||
&completion.new_text,
|
if old_range.len() != completion.new_text.len()
|
||||||
cx,
|
|| !snapshot.contains_str_at(old_range.start, &completion.new_text)
|
||||||
);
|
{
|
||||||
|
drop(snapshot);
|
||||||
|
buffer.edit_with_autoindent([old_range], &completion.new_text, cx);
|
||||||
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1888,7 +1888,9 @@ impl Buffer {
|
||||||
.await?;
|
.await?;
|
||||||
if let Some(additional_edits) = resolved_completion.additional_text_edits {
|
if let Some(additional_edits) = resolved_completion.additional_text_edits {
|
||||||
this.update(&mut cx, |this, cx| {
|
this.update(&mut cx, |this, cx| {
|
||||||
this.avoid_grouping_next_transaction();
|
if !push_to_history {
|
||||||
|
this.avoid_grouping_next_transaction();
|
||||||
|
}
|
||||||
this.start_transaction();
|
this.start_transaction();
|
||||||
let edit_ids = this.apply_lsp_edits(additional_edits, cx);
|
let edit_ids = this.apply_lsp_edits(additional_edits, cx);
|
||||||
if let Some(transaction_id) = this.end_transaction(cx) {
|
if let Some(transaction_id) = this.end_transaction(cx) {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue