Avoid finalizing transactions inside Buffer::apply_diff
This commit is contained in:
parent
ff85bc6d42
commit
7faa0da5c7
3 changed files with 10 additions and 13 deletions
|
@ -569,7 +569,9 @@ impl Buffer {
|
||||||
.read_with(&cx, |this, cx| this.diff(new_text, cx))
|
.read_with(&cx, |this, cx| this.diff(new_text, cx))
|
||||||
.await;
|
.await;
|
||||||
this.update(&mut cx, |this, cx| {
|
this.update(&mut cx, |this, cx| {
|
||||||
if let Some(transaction) = this.apply_diff(diff, cx).cloned() {
|
this.finalize_last_transaction();
|
||||||
|
this.apply_diff(diff, cx);
|
||||||
|
if let Some(transaction) = this.finalize_last_transaction().cloned() {
|
||||||
this.did_reload(
|
this.did_reload(
|
||||||
this.version(),
|
this.version(),
|
||||||
this.as_rope().fingerprint(),
|
this.as_rope().fingerprint(),
|
||||||
|
@ -1172,20 +1174,15 @@ impl Buffer {
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn apply_diff(&mut self, diff: Diff, cx: &mut ModelContext<Self>) -> Option<&Transaction> {
|
pub fn apply_diff(&mut self, diff: Diff, cx: &mut ModelContext<Self>) -> Option<TransactionId> {
|
||||||
if self.version != diff.base_version {
|
if self.version == diff.base_version {
|
||||||
|
self.apply_non_conflicting_portion_of_diff(diff, cx)
|
||||||
|
} else {
|
||||||
return None;
|
return None;
|
||||||
}
|
}
|
||||||
|
|
||||||
self.finalize_last_transaction();
|
|
||||||
self.start_transaction();
|
|
||||||
self.text.set_line_ending(diff.line_ending);
|
|
||||||
self.edit(diff.edits, None, cx);
|
|
||||||
self.end_transaction(cx)?;
|
|
||||||
self.finalize_last_transaction()
|
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn apply_diff_force(
|
pub fn apply_non_conflicting_portion_of_diff(
|
||||||
&mut self,
|
&mut self,
|
||||||
diff: Diff,
|
diff: Diff,
|
||||||
cx: &mut ModelContext<Self>,
|
cx: &mut ModelContext<Self>,
|
||||||
|
|
|
@ -254,7 +254,7 @@ async fn test_normalize_whitespace(cx: &mut gpui::TestAppContext) {
|
||||||
let format_diff = format.await;
|
let format_diff = format.await;
|
||||||
buffer.update(cx, |buffer, cx| {
|
buffer.update(cx, |buffer, cx| {
|
||||||
let version_before_format = format_diff.base_version.clone();
|
let version_before_format = format_diff.base_version.clone();
|
||||||
buffer.apply_diff_force(format_diff, cx);
|
buffer.apply_non_conflicting_portion_of_diff(format_diff, cx);
|
||||||
|
|
||||||
// The outcome depends on the order of concurrent taks.
|
// The outcome depends on the order of concurrent taks.
|
||||||
//
|
//
|
||||||
|
|
|
@ -2906,7 +2906,7 @@ impl Project {
|
||||||
.await;
|
.await;
|
||||||
buffer.update(&mut cx, move |buffer, cx| {
|
buffer.update(&mut cx, move |buffer, cx| {
|
||||||
buffer.finalize_last_transaction();
|
buffer.finalize_last_transaction();
|
||||||
buffer.apply_diff_force(diff, cx)
|
buffer.apply_non_conflicting_portion_of_diff(diff, cx)
|
||||||
})
|
})
|
||||||
} else {
|
} else {
|
||||||
None
|
None
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue