mirror of
https://github.com/zed-industries/zed.git
synced 2024-11-10 05:37:29 +03:00
Avoid finalizing transactions inside Buffer::apply_diff
This commit is contained in:
parent
ff85bc6d42
commit
7faa0da5c7
@ -569,7 +569,9 @@ impl Buffer {
|
||||
.read_with(&cx, |this, cx| this.diff(new_text, cx))
|
||||
.await;
|
||||
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.version(),
|
||||
this.as_rope().fingerprint(),
|
||||
@ -1172,20 +1174,15 @@ impl Buffer {
|
||||
})
|
||||
}
|
||||
|
||||
pub fn apply_diff(&mut self, diff: Diff, cx: &mut ModelContext<Self>) -> Option<&Transaction> {
|
||||
if self.version != diff.base_version {
|
||||
pub fn apply_diff(&mut self, diff: Diff, cx: &mut ModelContext<Self>) -> Option<TransactionId> {
|
||||
if self.version == diff.base_version {
|
||||
self.apply_non_conflicting_portion_of_diff(diff, cx)
|
||||
} else {
|
||||
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,
|
||||
diff: Diff,
|
||||
cx: &mut ModelContext<Self>,
|
||||
|
@ -254,7 +254,7 @@ async fn test_normalize_whitespace(cx: &mut gpui::TestAppContext) {
|
||||
let format_diff = format.await;
|
||||
buffer.update(cx, |buffer, cx| {
|
||||
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.
|
||||
//
|
||||
|
@ -2906,7 +2906,7 @@ impl Project {
|
||||
.await;
|
||||
buffer.update(&mut cx, move |buffer, cx| {
|
||||
buffer.finalize_last_transaction();
|
||||
buffer.apply_diff_force(diff, cx)
|
||||
buffer.apply_non_conflicting_portion_of_diff(diff, cx)
|
||||
})
|
||||
} else {
|
||||
None
|
||||
|
Loading…
Reference in New Issue
Block a user