|
|
@@ -654,6 +654,13 @@ export function changeAttribute( attributeCreator ) {
|
|
|
attributeCreator = attributeCreator || ( ( value, data ) => ( { value, key: data.attributeKey } ) );
|
|
|
|
|
|
return ( evt, data, conversionApi ) => {
|
|
|
+ const oldAttribute = attributeCreator( data.attributeOldValue, data );
|
|
|
+ const newAttribute = attributeCreator( data.attributeNewValue, data );
|
|
|
+
|
|
|
+ if ( !oldAttribute && !newAttribute ) {
|
|
|
+ return;
|
|
|
+ }
|
|
|
+
|
|
|
if ( !conversionApi.consumable.consume( data.item, evt.name ) ) {
|
|
|
return;
|
|
|
}
|
|
|
@@ -662,8 +669,6 @@ export function changeAttribute( attributeCreator ) {
|
|
|
const viewWriter = conversionApi.writer;
|
|
|
|
|
|
// First remove the old attribute if there was one.
|
|
|
- const oldAttribute = attributeCreator( data.attributeOldValue, data );
|
|
|
-
|
|
|
if ( data.attributeOldValue !== null && oldAttribute ) {
|
|
|
if ( oldAttribute.key == 'class' ) {
|
|
|
const classes = Array.isArray( oldAttribute.value ) ? oldAttribute.value : [ oldAttribute.value ];
|
|
|
@@ -682,9 +687,7 @@ export function changeAttribute( attributeCreator ) {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- // Then, if conversion was successful, set the new attribute.
|
|
|
- const newAttribute = attributeCreator( data.attributeNewValue, data );
|
|
|
-
|
|
|
+ // Then set the new attribute.
|
|
|
if ( data.attributeNewValue !== null && newAttribute ) {
|
|
|
if ( newAttribute.key == 'class' ) {
|
|
|
const classes = Array.isArray( newAttribute.value ) ? newAttribute.value : [ newAttribute.value ];
|