Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixed crash after text nodes got merged in insertContent while inserting a link #8486

Merged
merged 1 commit into from
Nov 24, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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