ソースを参照

Pasting a URL when a media element is selected will replace the URL for the media.

Kamil Piechaczek 7 年 前
コミット
1ccaa1be51

+ 4 - 0
packages/ckeditor5-media-embed/src/automediaembed.js

@@ -119,6 +119,10 @@ export default class AutoMediaEmbed extends Plugin {
 		let url = '';
 
 		for ( const node of walker ) {
+			if ( !node.item.is( 'textProxy' ) ) {
+				continue;
+			}
+
 			url += node.item.data;
 		}
 

+ 15 - 0
packages/ckeditor5-media-embed/tests/automediaembed.js

@@ -302,6 +302,21 @@ describe( 'AutoMediaEmbed - integration', () => {
 			);
 		} );
 
+		it( 'replaces a URL in media if pasted a link when other media element was selected', () => {
+			setData(
+				editor.model,
+				'[<media url="https://open.spotify.com/album/2IXlgvecaDqOeF3viUZnPI?si=ogVw7KlcQAGZKK4Jz9QzvA"></media>]'
+			);
+
+			pasteHtml( editor, 'https://www.youtube.com/watch?v=H08tGjXNHO4' );
+
+			clock.tick( 100 );
+
+			expect( getData( editor.model ) ).to.equal(
+				'[<media url="https://www.youtube.com/watch?v=H08tGjXNHO4"></media>]'
+			);
+		} );
+
 		it( 'does nothing if URL match to media but it was removed', () => {
 			return ClassicTestEditor
 				.create( editorElement, {