Skip to content

Commit

Permalink
Merge pull request #8486 from ckeditor/i/8210
Browse files Browse the repository at this point in the history
Fix (link): Editor should not crash after inserting a link after another link with the same URL. Closes #8210.
  • Loading branch information
jodator committed Nov 24, 2020
2 parents 2151b57 + 528e000 commit 81b8dc6
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 4 deletions.
7 changes: 3 additions & 4 deletions packages/ckeditor5-link/src/linkcommand.js
Original file line number Diff line number Diff line change
Expand Up @@ -198,12 +198,11 @@ export default class LinkCommand extends Command {
attributes.set( item, true );
} );

const node = writer.createText( href, attributes );

model.insertContent( node, position );
const { end: positionAfter } = model.insertContent( writer.createText( href, attributes ), position );

// Put the selection at the end of the inserted link.
writer.setSelection( writer.createPositionAfter( node ) );
// Using end of range returned from insertContent in case nodes with the same attributes got merged.
writer.setSelection( positionAfter );
}

// Remove the `linkHref` attribute and all link decorators from the selection.
Expand Down
11 changes: 11 additions & 0 deletions packages/ckeditor5-link/tests/linkcommand.js
Original file line number Diff line number Diff line change
Expand Up @@ -401,6 +401,17 @@ describe( 'LinkCommand', () => {

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

// https://github.com/ckeditor/ckeditor5/issues/8210
it( 'should insert text with `linkHref` attribute just after text node with the same `linkHref` attribute', () => {
setData( model, '<$text linkHref="url">foo</$text>[]bar' );

model.change( writer => writer.overrideSelectionGravity() );

command.execute( 'url' );

expect( getData( model ) ).to.equal( '<$text linkHref="url">foourl</$text>[]bar' );
} );
} );
} );

Expand Down

0 comments on commit 81b8dc6

Please sign in to comment.