@@ -3884,7 +3884,7 @@ async fn test_buffer_is_dirty(cx: &mut gpui::TestAppContext) {
3884
3884
]
3885
3885
) ;
3886
3886
3887
- // When a file is deleted, the buffer is considered dirty.
3887
+ // When a file is deleted, it is not considered dirty.
3888
3888
let events = Arc :: new ( Mutex :: new ( Vec :: new ( ) ) ) ;
3889
3889
let buffer2 = project
3890
3890
. update ( cx, |p, cx| p. open_local_buffer ( path ! ( "/dir/file2" ) , cx) )
@@ -3893,7 +3893,10 @@ async fn test_buffer_is_dirty(cx: &mut gpui::TestAppContext) {
3893
3893
buffer2. update ( cx, |_, cx| {
3894
3894
cx. subscribe ( & buffer2, {
3895
3895
let events = events. clone ( ) ;
3896
- move |_, _, event, _| events. lock ( ) . push ( event. clone ( ) )
3896
+ move |_, _, event, _| match event {
3897
+ BufferEvent :: Operation { .. } => { }
3898
+ _ => events. lock ( ) . push ( event. clone ( ) ) ,
3899
+ }
3897
3900
} )
3898
3901
. detach ( ) ;
3899
3902
} ) ;
@@ -3902,12 +3905,37 @@ async fn test_buffer_is_dirty(cx: &mut gpui::TestAppContext) {
3902
3905
. await
3903
3906
. unwrap ( ) ;
3904
3907
cx. executor ( ) . run_until_parked ( ) ;
3905
- buffer2. update ( cx, |buffer, _| assert ! ( buffer. is_dirty( ) ) ) ;
3908
+ buffer2. update ( cx, |buffer, _| assert ! ( !buffer. is_dirty( ) ) ) ;
3909
+ assert_eq ! (
3910
+ mem:: take( & mut * events. lock( ) ) ,
3911
+ & [ language:: BufferEvent :: FileHandleChanged ]
3912
+ ) ;
3913
+
3914
+ // Buffer becomes dirty when edited.
3915
+ buffer2. update ( cx, |buffer, cx| {
3916
+ buffer. edit ( [ ( 2 ..3 , "" ) ] , None , cx) ;
3917
+ assert_eq ! ( buffer. is_dirty( ) , true ) ;
3918
+ } ) ;
3919
+ assert_eq ! (
3920
+ mem:: take( & mut * events. lock( ) ) ,
3921
+ & [
3922
+ language:: BufferEvent :: Edited ,
3923
+ language:: BufferEvent :: DirtyChanged
3924
+ ]
3925
+ ) ;
3926
+
3927
+ // Buffer becomes clean again when all of its content is removed, because
3928
+ // the file was deleted.
3929
+ buffer2. update ( cx, |buffer, cx| {
3930
+ buffer. edit ( [ ( 0 ..2 , "" ) ] , None , cx) ;
3931
+ assert_eq ! ( buffer. is_empty( ) , true ) ;
3932
+ assert_eq ! ( buffer. is_dirty( ) , false ) ;
3933
+ } ) ;
3906
3934
assert_eq ! (
3907
3935
* events. lock( ) ,
3908
3936
& [
3909
- language:: BufferEvent :: DirtyChanged ,
3910
- language:: BufferEvent :: FileHandleChanged
3937
+ language:: BufferEvent :: Edited ,
3938
+ language:: BufferEvent :: DirtyChanged
3911
3939
]
3912
3940
) ;
3913
3941
@@ -3920,7 +3948,10 @@ async fn test_buffer_is_dirty(cx: &mut gpui::TestAppContext) {
3920
3948
buffer3. update ( cx, |_, cx| {
3921
3949
cx. subscribe ( & buffer3, {
3922
3950
let events = events. clone ( ) ;
3923
- move |_, _, event, _| events. lock ( ) . push ( event. clone ( ) )
3951
+ move |_, _, event, _| match event {
3952
+ BufferEvent :: Operation { .. } => { }
3953
+ _ => events. lock ( ) . push ( event. clone ( ) ) ,
3954
+ }
3924
3955
} )
3925
3956
. detach ( ) ;
3926
3957
} ) ;
0 commit comments