Skip to content

Commit

Permalink
Formatting
Browse files Browse the repository at this point in the history
  • Loading branch information
adzialocha committed Dec 10, 2024
1 parent f255e4a commit fe482b9
Showing 1 changed file with 43 additions and 43 deletions.
86 changes: 43 additions & 43 deletions src/application.rs
Original file line number Diff line number Diff line change
Expand Up @@ -101,54 +101,54 @@ mod imp {
let application = self.obj();

// Get the current window or create one if necessary
let window = self
.window
.get_or_init(|| {
let window = AardvarkWindow::new(&*application);
let mut rx = application.imp().rx.take().expect("rx should be given at this point");

{
let window = window.clone();
let application = application.clone();

glib::spawn_future_local(async move {
while let Some(bytes) = rx.recv().await {
let document = &application.imp().document;

// Apply remote changes to our local text CRDT
if let Err(err) = document.load_incremental(&bytes) {
eprintln!("failed applying text change from remote peer to automerge document: {err}");
continue;
}
let window = self.window.get_or_init(|| {
let window = AardvarkWindow::new(&*application);
let mut rx = application
.imp()
.rx
.take()
.expect("rx should be given at this point");

{
let window = window.clone();
let application = application.clone();

glib::spawn_future_local(async move {
while let Some(bytes) = rx.recv().await {
let document = &application.imp().document;

// Apply remote changes to our local text CRDT
if let Err(err) = document.load_incremental(&bytes) {
eprintln!(
"failed applying text change from remote peer to automerge document: {err}"
);
continue;
}

// Get latest changes and apply them to our local text buffer
for patch in document.diff_incremental() {
match &patch.action {
PatchAction::SpliceText {
index,
value,
..
} => {
window.splice_text_view(
*index as i32,
0,
value.make_string().as_str(),
);
}
PatchAction::DeleteSeq { index, length } => {
window.splice_text_view(*index as i32, *length as i32, "");
}
_ => (),
// Get latest changes and apply them to our local text buffer
for patch in document.diff_incremental() {
match &patch.action {
PatchAction::SpliceText { index, value, .. } => {
window.splice_text_view(
*index as i32,
0,
value.make_string().as_str(),
);
}
PatchAction::DeleteSeq { index, length } => {
window.splice_text_view(*index as i32, *length as i32, "");
}
_ => (),
}

dbg!(document.text());
}
});
}

window
});
dbg!(document.text());
}
});
}

window
});

{
let application = application.clone();
Expand Down

0 comments on commit fe482b9

Please sign in to comment.