Skip to content

Commit

Permalink
Fixed crash after text nodes got merged in insertContent while insert…
Browse files Browse the repository at this point in the history
…ing a link.
  • Loading branch information
niegowski committed Nov 19, 2020
1 parent 23c64f5 commit 528e000
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 528e000

Please sign in to comment.