瀏覽代碼

Merge branch 'master' into t/ckeditor5-ui/144

Aleksander Nowodzinski 8 年之前
父節點
當前提交
b6a3876831

+ 9 - 5
packages/ckeditor5-link/src/linkcommand.js

@@ -8,9 +8,9 @@
  */
 
 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 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}.
@@ -69,16 +69,20 @@ export default class LinkCommand extends Command {
 					// Then update `linkHref` value.
 					const linkRange = findLinkRange( selection.getFirstPosition(), selection.getAttribute( 'linkHref' ) );
 
-					batch.setAttribute( linkRange, 'linkHref', href );
+					batch.setAttribute( 'linkHref', href, linkRange );
 
 					// Create new range wrapping changed link.
 					selection.setRanges( [ linkRange ] );
 				}
 				// If not then insert text node with `linkHref` attribute in place of caret.
 				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.
 					selection.setRanges( [ Range.createOn( node ) ] );
@@ -89,7 +93,7 @@ export default class LinkCommand extends Command {
 				const ranges = doc.schema.getValidRanges( selection.getRanges(), 'linkHref' );
 
 				for ( const range of ranges ) {
-					batch.setAttribute( range, 'linkHref', href );
+					batch.setAttribute( 'linkHref', href, range );
 				}
 			}
 		} );

+ 1 - 1
packages/ckeditor5-link/src/unlinkcommand.js

@@ -45,7 +45,7 @@ export default class UnlinkCommand extends Command {
 
 			// Remove `linkHref` attribute from specified ranges.
 			for ( const range of rangesToUnlink ) {
-				batch.removeAttribute( range, 'linkHref' );
+				batch.removeAttribute( 'linkHref', range );
 			}
 		} );
 	}

+ 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' );
 			} );
 
+			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', () => {
 				setData( document, '<$text linkHref="other url">foo[]bar</$text>' );