@@ -165,9 +165,10 @@ function changeItem( batch, doc, key, value, item ) {
165165 let range , operation ;
166166
167167 const delta = item . is ( 'rootElement' ) ? new RootAttributeDelta ( ) : new AttributeDelta ( ) ;
168- batch . addDelta ( delta ) ;
169168
170169 if ( previousValue != value ) {
170+ batch . addDelta ( delta ) ;
171+
171172 if ( item . is ( 'rootElement' ) ) {
172173 // If we change attributes of root element, we have to use `RootAttributeOperation`.
173174 operation = new RootAttributeOperation ( item , key , previousValue , value , doc . version ) ;
@@ -195,7 +196,6 @@ function changeItem( batch, doc, key, value, item ) {
195196// into smaller parts.
196197function changeRange ( batch , doc , attributeKey , attributeValue , range ) {
197198 const delta = new AttributeDelta ( ) ;
198- batch . addDelta ( delta ) ;
199199
200200 // Position of the last split, the beginning of the new range.
201201 let lastSplitPosition = range . start ;
@@ -233,6 +233,11 @@ function changeRange( batch, doc, attributeKey, attributeValue, range ) {
233233 }
234234
235235 function addOperation ( ) {
236+ // Add delta to the batch only if there is at least operation in the delta. Add delta only once.
237+ if ( delta . operations . length === 0 ) {
238+ batch . addDelta ( delta ) ;
239+ }
240+
236241 let range = new Range ( lastSplitPosition , position ) ;
237242 const operation = new AttributeOperation ( range , attributeKey , attributeValueBefore , attributeValue , doc . version ) ;
238243
0 commit comments