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

Commit

Permalink
Fixed: Link feature was creating empty text nodes with linkHref att…
Browse files Browse the repository at this point in the history
…ribute.
  • Loading branch information
scofalik committed Feb 21, 2018
1 parent 592d38c commit c1c7feb
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 1 deletion.
4 changes: 3 additions & 1 deletion src/linkcommand.js
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,9 @@ export default class LinkCommand extends Command {
writer.setSelection( linkRange );
}
// If not then insert text node with `linkHref` attribute in place of caret.
else {
// However, since selection in 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() );

attributes.set( 'linkHref', href );
Expand Down
8 changes: 8 additions & 0 deletions tests/linkcommand.js
Original file line number Diff line number Diff line change
Expand Up @@ -249,6 +249,14 @@ describe( 'LinkCommand', () => {

expect( getData( model ) ).to.equal( '<p>foo[]bar</p>' );
} );

it( 'should not insert text node if link is empty', () => {
setData( model, '<p>foo[]bar</p>' );

command.execute( '' );

expect( getData( model ) ).to.equal( '<p>foo[]bar</p>' );
} );
} );
} );
} );

0 comments on commit c1c7feb

Please sign in to comment.