Skip to content
This repository has been archived by the owner on Jun 26, 2020. It is now read-only.

Commit

Permalink
Merge 669c5fd into 71c4c19
Browse files Browse the repository at this point in the history
  • Loading branch information
f1ames committed Nov 23, 2018
2 parents 71c4c19 + 669c5fd commit f5b0d6c
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 0 deletions.
6 changes: 6 additions & 0 deletions src/conversion/downcast-converters.js
Original file line number Diff line number Diff line change
Expand Up @@ -685,6 +685,12 @@ export function changeAttribute( attributeCreator ) {
const viewElement = conversionApi.mapper.toViewElement( data.item );
const viewWriter = conversionApi.writer;

// If model item cannot be mapped to view element, it means item is not an `Element` instance (it is a `TextProxy`).
// Only elements can have attributes in a view so do not proceed for anything else (see #1587).
if ( !viewElement ) {
return;
}

// First remove the old attribute if there was one.
if ( data.attributeOldValue !== null && oldAttribute ) {
if ( oldAttribute.key == 'class' ) {
Expand Down
43 changes: 43 additions & 0 deletions tests/conversion/downcast-converters.js
Original file line number Diff line number Diff line change
Expand Up @@ -460,6 +460,49 @@ describe( 'downcast-helpers', () => {

expectResult( '<img class="styled-pull-out"></img>' );
} );

// #1587
it( 'config.view and config.model as strings in generic conversion (elements only)', () => {
conversion.for( 'downcast' ).add( downcastElementToElement( { model: 'paragraph', view: 'p' } ) );

conversion.for( 'downcast' ).add( downcastAttributeToAttribute( { model: 'test', view: 'test' } ) );

model.change( writer => {
writer.insertElement( 'paragraph', { test: '1' }, modelRoot, 0 );
writer.insertElement( 'paragraph', { test: '2' }, modelRoot, 1 );
} );

expectResult( '<p test="1"></p><p test="2"></p>' );

model.change( writer => {
writer.removeAttribute( 'test', modelRoot.getChild( 1 ) );
} );

expectResult( '<p test="1"></p><p></p>' );
} );

// #1587
it( 'config.view and config.model as strings in generic conversion (elements + text)', () => {
conversion.for( 'downcast' ).add( downcastElementToElement( { model: 'paragraph', view: 'p' } ) );

conversion.for( 'downcast' ).add( downcastAttributeToAttribute( { model: 'test', view: 'test' } ) );

model.change( writer => {
writer.insertElement( 'paragraph', modelRoot, 0 );
writer.insertElement( 'paragraph', { test: '1' }, modelRoot, 1 );

writer.insertText( 'Foo', { test: '2' }, modelRoot.getChild( 0 ), 0 );
writer.insertText( 'Bar', { test: '3' }, modelRoot.getChild( 1 ), 0 );
} );

expectResult( '<p>Foo</p><p test="1">Bar</p>' );

model.change( writer => {
writer.removeAttribute( 'test', modelRoot.getChild( 1 ) );
} );

expectResult( '<p>Foo</p><p>Bar</p>' );
} );
} );

describe( 'downcastMarkerToElement', () => {
Expand Down

0 comments on commit f5b0d6c

Please sign in to comment.