20
20
21
21
use std:: cell:: { OnceCell , RefCell } ;
22
22
23
+ use aardvark_doc:: { TextCrdt , TextCrdtEvent } ;
23
24
use aardvark_node:: network;
24
25
use adw:: prelude:: * ;
25
26
use adw:: subclass:: prelude:: * ;
26
27
use gettextrs:: gettext;
27
28
use gtk:: { gio, glib} ;
28
29
use tokio:: sync:: { mpsc, oneshot} ;
29
- use automerge:: PatchAction ;
30
30
31
31
use crate :: config:: VERSION ;
32
- use crate :: document:: Document ;
33
32
use crate :: glib:: closure_local;
34
33
use crate :: { AardvarkTextBuffer , AardvarkWindow } ;
35
34
@@ -46,8 +45,7 @@ mod imp {
46
45
backend_shutdown : oneshot:: Sender < ( ) > ,
47
46
}
48
47
49
- impl AardvarkApplication {
50
- }
48
+ impl AardvarkApplication { }
51
49
52
50
#[ glib:: object_subclass]
53
51
impl ObjectSubclass for AardvarkApplication {
@@ -182,24 +180,16 @@ impl AardvarkApplication {
182
180
183
181
// Apply remote changes to our local text CRDT
184
182
if let Err ( err) = document. load_incremental ( & message) {
185
- eprintln ! (
186
- "failed applying text change from remote peer to automerge document: {err}"
187
- ) ;
188
- window. add_toast ( adw:: Toast :: new (
189
- "The network provided bad data!"
190
- ) ) ;
183
+ eprintln ! ( "failed applying text change from remote peer to automerge document: {err}" ) ;
184
+ window. add_toast ( adw:: Toast :: new ( "The network provided bad data!" ) ) ;
191
185
return ;
192
186
}
193
187
194
188
// Get latest changes and apply them to our local text buffer
195
189
for patch in document. diff_incremental ( ) {
196
190
match & patch. action {
197
191
PatchAction :: SpliceText { index, value, .. } => {
198
- buffer. splice (
199
- * index as i32 ,
200
- 0 ,
201
- value. make_string ( ) . as_str ( ) ,
202
- ) ;
192
+ buffer. splice ( * index as i32 , 0 , value. make_string ( ) . as_str ( ) ) ;
203
193
}
204
194
PatchAction :: DeleteSeq { index, length } => {
205
195
buffer. splice ( * index as i32 , * length as i32 , "" ) ;
@@ -210,7 +200,9 @@ impl AardvarkApplication {
210
200
211
201
// Sanity check that the text buffer and CRDT are in the same state
212
202
if buffer. full_text ( ) != document. text ( ) {
213
- window. add_toast ( adw:: Toast :: new ( "The CRDT and the text view have different states!" ) ) ;
203
+ window. add_toast ( adw:: Toast :: new (
204
+ "The CRDT and the text view have different states!" ,
205
+ ) ) ;
214
206
// if the state diverged, use the CRDT as the source of truth
215
207
buffer. set_text ( & document. text ( ) ) ;
216
208
}
0 commit comments