From 2406704f9d9734bcc6aeee8873f75d5971150e26 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pawe=C5=82=20Kwa=C5=9Bnik?= Date: Thu, 11 Mar 2021 14:37:11 +0100 Subject: [PATCH] Fixing target=_blank duplicates after clicking on it in the documentation example. --- packages/ckeditor5-link/src/linkediting.js | 1 + packages/ckeditor5-link/tests/linkediting.js | 16 ++++++++++++++++ 2 files changed, 17 insertions(+) diff --git a/packages/ckeditor5-link/src/linkediting.js b/packages/ckeditor5-link/src/linkediting.js index cf24b118235..5bcae244161 100644 --- a/packages/ckeditor5-link/src/linkediting.js +++ b/packages/ckeditor5-link/src/linkediting.js @@ -516,6 +516,7 @@ export default class LinkEditing extends Plugin { // @param {module:utils/collection~Collection} manualDecorators function removeLinkAttributesFromSelection( writer, manualDecorators ) { writer.removeSelectionAttribute( 'linkHref' ); + writer.removeSelectionAttribute( 'linkTarget' ); for ( const decorator of manualDecorators ) { writer.removeSelectionAttribute( decorator.id ); diff --git a/packages/ckeditor5-link/tests/linkediting.js b/packages/ckeditor5-link/tests/linkediting.js index cced56d0e57..bf4e8deaa9f 100644 --- a/packages/ckeditor5-link/tests/linkediting.js +++ b/packages/ckeditor5-link/tests/linkediting.js @@ -158,6 +158,22 @@ describe( 'LinkEditing', () => { expect( [ ...model.document.selection.getAttributeKeys() ] ).to.be.empty; } ); + it( 'should remove linkTarget attribute when pasting a link', () => { + editor.model.schema.extend( '$text', { allowAttributes: 'linkTarget' } ); + + setModelData( model, 'foo[]' ); + + model.change( writer => { + model.insertContent( writer.createText( 'INSERTED', { linkHref: 'ckeditor.com', linkTarget: '_blank' } ) ); + } ); + + expect( getModelData( model ) ).to.equal( + 'foo<$text linkHref="ckeditor.com" linkTarget="_blank">INSERTED[]' + ); + + expect( [ ...model.document.selection.getAttributeKeys() ] ).to.be.empty; + } ); + it( 'should remove all attributes starting with "link" (e.g. decorator attributes) when pasting a link', () => { setModelData( model, 'foo[]' );