diff --git a/packages/ckeditor5-link/src/linkcommand.js b/packages/ckeditor5-link/src/linkcommand.js index f9703437541..6932ae5e16e 100644 --- a/packages/ckeditor5-link/src/linkcommand.js +++ b/packages/ckeditor5-link/src/linkcommand.js @@ -187,7 +187,7 @@ export default class LinkCommand extends Command { writer.setSelection( writer.createPositionAfter( linkRange.end.nodeBefore ) ); } // If not then insert text node with `linkHref` attribute in place of caret. - // However, since selection in collapsed, attribute value will be used as data for text node. + // However, since selection is collapsed, attribute value will be used as data for text node. // So, if `href` is empty, do not create text node. else if ( href !== '' ) { const attributes = toMap( selection.getAttributes() ); diff --git a/packages/ckeditor5-link/src/linkimageediting.js b/packages/ckeditor5-link/src/linkimageediting.js index 0a36adafaff..abf165038b3 100644 --- a/packages/ckeditor5-link/src/linkimageediting.js +++ b/packages/ckeditor5-link/src/linkimageediting.js @@ -214,6 +214,13 @@ function downcastImageLinkManualDecorator( manualDecorators, decorator ) { const viewFigure = conversionApi.mapper.toViewElement( data.item ); const linkInImage = Array.from( viewFigure.getChildren() ).find( child => child.name === 'a' ); + // The element was removed by the time this converter is executed. + // It may happen when the base `linkHref` and decorator attributes are removed + // at the same time (see #8401). + if ( !linkInImage ) { + return; + } + for ( const [ key, val ] of toMap( attributes ) ) { conversionApi.writer.setAttribute( key, val, linkInImage ); } diff --git a/packages/ckeditor5-link/tests/linkimageediting.js b/packages/ckeditor5-link/tests/linkimageediting.js index 51c980fa025..f0c9e16c7ba 100644 --- a/packages/ckeditor5-link/tests/linkimageediting.js +++ b/packages/ckeditor5-link/tests/linkimageediting.js @@ -826,6 +826,81 @@ describe( 'LinkImageEditing', () => { '
' ); } ); + + // See #8401. + it( 'should downcast without error if the image already has no link', () => { + setModelData( model, + '[