소스 검색

Aligned code with new Batch API.

Oskar Wróbel 8 년 전
부모
커밋
fe3e7d65b6
2개의 변경된 파일17개의 추가작업 그리고 3개의 파일을 삭제
  1. 7 3
      packages/ckeditor5-link/src/linkcommand.js
  2. 10 0
      packages/ckeditor5-link/tests/linkcommand.js

+ 7 - 3
packages/ckeditor5-link/src/linkcommand.js

@@ -8,9 +8,9 @@
  */
  */
 
 
 import Command from '@ckeditor/ckeditor5-core/src/command';
 import Command from '@ckeditor/ckeditor5-core/src/command';
-import Text from '@ckeditor/ckeditor5-engine/src/model/text';
 import Range from '@ckeditor/ckeditor5-engine/src/model/range';
 import Range from '@ckeditor/ckeditor5-engine/src/model/range';
 import findLinkRange from './findlinkrange';
 import findLinkRange from './findlinkrange';
+import toMap from '@ckeditor/ckeditor5-utils/src/tomap';
 
 
 /**
 /**
  * The link command. It is used by the {@link module:link/link~Link link feature}.
  * The link command. It is used by the {@link module:link/link~Link link feature}.
@@ -76,9 +76,13 @@ export default class LinkCommand extends Command {
 				}
 				}
 				// If not then insert text node with `linkHref` attribute in place of caret.
 				// If not then insert text node with `linkHref` attribute in place of caret.
 				else {
 				else {
-					const node = new Text( href, { linkHref: href } );
+					const attributes = toMap( doc.selection.getAttributes() );
 
 
-					batch.insert( position, node );
+					attributes.set( 'linkHref', href );
+
+					const node = batch.createText( href, attributes );
+
+					batch.insert( node, position );
 
 
 					// Create new range wrapping created node.
 					// Create new range wrapping created node.
 					selection.setRanges( [ Range.createOn( node ) ] );
 					selection.setRanges( [ Range.createOn( node ) ] );

+ 10 - 0
packages/ckeditor5-link/tests/linkcommand.js

@@ -213,6 +213,16 @@ describe( 'LinkCommand', () => {
 				expect( getData( document ) ).to.equal( 'foo[<$text linkHref="url">url</$text>]bar' );
 				expect( getData( document ) ).to.equal( 'foo[<$text linkHref="url">url</$text>]bar' );
 			} );
 			} );
 
 
+			it( 'should insert text with `linkHref` attribute, and selection attributes', () => {
+				setData( document, '<$text bold="true">foo[]bar</$text>', {
+					selectionAttributes: { bold: true }
+				} );
+
+				command.execute( 'url' );
+
+				expect( getData( document ) ).to.equal( '<$text bold="true">foo[<$text linkHref="url">url</$text>]bar</$text>' );
+			} );
+
 			it( 'should update `linkHref` attribute and select whole link when selection is inside text with `linkHref` attribute', () => {
 			it( 'should update `linkHref` attribute and select whole link when selection is inside text with `linkHref` attribute', () => {
 				setData( document, '<$text linkHref="other url">foo[]bar</$text>' );
 				setData( document, '<$text linkHref="other url">foo[]bar</$text>' );