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

Commit

Permalink
Merge pull request #170 from ckeditor/t/169
Browse files Browse the repository at this point in the history
Fix: Link feature was creating empty text nodes with `linkHref` attribute. Closes #169.
  • Loading branch information
Reinmar committed Feb 26, 2018
2 parents 592d38c + c1c7feb commit 0641978
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 0641978

Please sign in to comment.