@@ -782,6 +782,140 @@ describe( 'Differ', () => {
782
782
} ) ;
783
783
} ) ;
784
784
785
+ it ( 'attribute changes intersecting #1' , ( ) => {
786
+ const parent = root . getChild ( 1 ) ;
787
+
788
+ // Be aware that you cannot make an intersecting changes with the same attribute key,
789
+ // cause the value would be incorrect for the common part of the ranges.
790
+ const ranges = [
791
+ [ 0 , 2 , null , true , 'foo' ] ,
792
+ [ 1 , 3 , null , true , 'bar' ]
793
+ ] ;
794
+
795
+ model . change ( ( ) => {
796
+ for ( const item of ranges ) {
797
+ const range = Range . createFromParentsAndOffsets ( parent , item [ 0 ] , parent , item [ 1 ] ) ;
798
+
799
+ attribute ( range , item [ 4 ] , item [ 2 ] , item [ 3 ] ) ;
800
+ }
801
+
802
+ expectChanges ( [
803
+ {
804
+ type : 'attribute' ,
805
+ range : Range . createFromParentsAndOffsets ( parent , 0 , parent , 2 ) ,
806
+ attributeKey : 'foo' ,
807
+ attributeOldValue : null ,
808
+ attributeNewValue : true
809
+ } ,
810
+ {
811
+ type : 'attribute' ,
812
+ range : Range . createFromParentsAndOffsets ( parent , 1 , parent , 3 ) ,
813
+ attributeKey : 'bar' ,
814
+ attributeOldValue : null ,
815
+ attributeNewValue : true
816
+ }
817
+ ] ) ;
818
+ } ) ;
819
+ } ) ;
820
+
821
+ it ( 'attribute changes intersecting #2' , ( ) => {
822
+ const parent = root . getChild ( 1 ) ;
823
+
824
+ // Be aware that you cannot make an intersecting changes with the same attribute key,
825
+ // cause the value would be incorrect for the common part of the ranges.
826
+ const ranges = [
827
+ [ 1 , 3 , null , true , 'foo' ] ,
828
+ [ 0 , 2 , null , true , 'bar' ]
829
+ ] ;
830
+
831
+ model . change ( ( ) => {
832
+ for ( const item of ranges ) {
833
+ const range = Range . createFromParentsAndOffsets ( parent , item [ 0 ] , parent , item [ 1 ] ) ;
834
+
835
+ attribute ( range , item [ 4 ] , item [ 2 ] , item [ 3 ] ) ;
836
+ }
837
+
838
+ expectChanges ( [
839
+ {
840
+ type : 'attribute' ,
841
+ range : Range . createFromParentsAndOffsets ( parent , 0 , parent , 1 ) ,
842
+ attributeKey : 'bar' ,
843
+ attributeOldValue : null ,
844
+ attributeNewValue : true
845
+ } ,
846
+ {
847
+ type : 'attribute' ,
848
+ range : Range . createFromParentsAndOffsets ( parent , 1 , parent , 2 ) ,
849
+ attributeKey : 'foo' ,
850
+ attributeOldValue : null ,
851
+ attributeNewValue : true
852
+ } ,
853
+ {
854
+ type : 'attribute' ,
855
+ range : Range . createFromParentsAndOffsets ( parent , 1 , parent , 2 ) ,
856
+ attributeKey : 'bar' ,
857
+ attributeOldValue : null ,
858
+ attributeNewValue : true
859
+ } ,
860
+ {
861
+ type : 'attribute' ,
862
+ range : Range . createFromParentsAndOffsets ( parent , 2 , parent , 3 ) ,
863
+ attributeKey : 'foo' ,
864
+ attributeOldValue : null ,
865
+ attributeNewValue : true
866
+ }
867
+ ] ) ;
868
+ } ) ;
869
+ } ) ;
870
+
871
+ it ( 'attribute changes included in an attribute change #1 - changes are reversed at the end' , ( ) => {
872
+ const parent = root . getChild ( 1 ) ;
873
+
874
+ const ranges = [
875
+ [ 0 , 1 , null , true ] ,
876
+ [ 1 , 2 , null , true ] ,
877
+ [ 0 , 2 , true , null ]
878
+ ] ;
879
+
880
+ model . change ( ( ) => {
881
+ for ( const item of ranges ) {
882
+ const range = Range . createFromParentsAndOffsets ( parent , item [ 0 ] , parent , item [ 1 ] ) ;
883
+
884
+ attribute ( range , attributeKey , item [ 2 ] , item [ 3 ] ) ;
885
+ }
886
+
887
+ expectChanges ( [ ] ) ;
888
+ } ) ;
889
+ } ) ;
890
+
891
+ it ( 'attribute changes included in an attribute change #2 - changes are re-applied at the end' , ( ) => {
892
+ const parent = root . getChild ( 1 ) ;
893
+
894
+ const ranges = [
895
+ [ 0 , 1 , null , true ] ,
896
+ [ 1 , 2 , null , true ] ,
897
+ [ 0 , 2 , true , null ] ,
898
+ [ 0 , 1 , null , true ] ,
899
+ [ 1 , 2 , null , true ]
900
+ ] ;
901
+
902
+ model . change ( ( ) => {
903
+ for ( const item of ranges ) {
904
+ const range = Range . createFromParentsAndOffsets ( parent , item [ 0 ] , parent , item [ 1 ] ) ;
905
+
906
+ attribute ( range , attributeKey , item [ 2 ] , item [ 3 ] ) ;
907
+ }
908
+
909
+ expectChanges ( [ {
910
+ type : 'attribute' ,
911
+ range : Range . createFromParentsAndOffsets ( parent , 0 , parent , 2 ) ,
912
+ attributeKey,
913
+ attributeOldValue : null ,
914
+ attributeNewValue : true
915
+ } ] ) ;
916
+ } ) ;
917
+ } ) ;
918
+
785
919
it ( 'on multiple non-consecutive characters in multiple operations' , ( ) => {
786
920
const parent = root . getChild ( 0 ) ;
787
921
0 commit comments