Skip to content
Permalink
Browse files

Merge branch 't/13532b'

  • Loading branch information...
pjasiun committed Jul 16, 2015
2 parents 7a6aa3b + e4f2d17 commit 0d71fa2b01467df50fe6f96152e25980cb900893
@@ -12,24 +12,34 @@
requires: 'autolink,undo',

init: function( editor ) {
var currentId = 1;
var currentId = 1,
embedCandidatePasted;

editor.on( 'paste', function( evt ) {
if ( evt.data.dataTransfer.getTransferType( editor ) == CKEDITOR.DATA_TRANSFER_INTERNAL ) {
embedCandidatePasted = 0;
return;
}

var match = evt.data.dataValue.match( validLinkRegExp );

embedCandidatePasted = match != null && decodeURI( match[ 1 ] ) == decodeURI( match[ 2 ] );

// Expecting exactly one <a> tag spanning the whole pasted content.
// The tag has to have same href as content.
if ( match != null && decodeURI( match[ 1 ] ) == decodeURI( match[ 2 ] ) ) {
if ( embedCandidatePasted ) {
evt.data.dataValue = '<a data-cke-autoembed="' + ( ++currentId ) + '"' + evt.data.dataValue.substr( 2 );
}
}, null, null, 20 ); // Execute after autolink.

editor.on( 'afterPaste', function() {
autoEmbedLink( editor, currentId );
// If one pasted an embeddable link and then undone the action, the link in the content holds the
// data-cke-autoembed attribute and may be embedded on *any* successive paste.
// This check ensures that autoEmbedLink is called only if afterPaste is fired *right after*
// embeddable link got into the content. (#13532)
if ( embedCandidatePasted ) {
autoEmbedLink( editor, currentId );
}
} );
}
} );
@@ -1,11 +1,13 @@
/* bender-tags: editor,unit */
/* bender-ckeditor-plugins: embed,autoembed,enterkey,undo,link */
/* bender-include: ../embedbase/_helpers/tools.js, ../clipboard/_helpers/pasting.js */
/* bender-include: ../embedbase/_helpers/tools.js, ../clipboard/_helpers/pasting.js, ../widget/_helpers/tools.js */

/* global embedTools, assertPasteEvent */
/* global embedTools, assertPasteEvent, widgetTestsTools */

'use strict';

var obj2Array = widgetTestsTools.obj2Array;

function correctJsonpCallback( urlTemplate, urlParams, callback ) {
callback( {
'url': decodeURIComponent( urlParams.url ),
@@ -265,5 +267,49 @@ bender.test( {
}, null, null, 900 );

this.editor.execCommand( 'paste', pastedText );
},

// #13532
'test re–embeddable url': function() {
var bot = this.editorBot,
editor = bot.editor;

jsonpCallback = function( urlTemplate, urlParams, callback ) {
resume( function() {
// Make the URL a nice widget.
callback( {
type: 'rich',
html: '<p>url:' + urlParams.url + '</p>'
} );

// Undo embedding. There's no widget, the link is in the content instead.
editor.execCommand( 'undo' );

// Will be pasting something after the link. Prepare a nice range.
var range = editor.createRange();
range.moveToPosition( editor.editable().findOne( 'a' ), CKEDITOR.POSITION_AFTER_END );
range.select();

// Make sure transfer type for the next paste is CKEDITOR.DATA_TRANSFER_INTERNAL to
// avoid processing of pasted data.
editor.once( 'paste', function( evt ) {
evt.data.dataTransfer.sourceEditor = editor;
}, null, null, 1 );

// Paste anything to check if the embeddable link, which used to
// be a widget before 'undo' was called is re–embedded. It shouldn't be.
editor.execCommand( 'paste', 'y' );

wait( function() {
assert.areEqual( 0, obj2Array( editor.widgets.instances ).length, 'Link should not be re–embedded.' );
}, 200 );
} );
};

bot.setData( '', function() {
// Paste any embeddable URL.
this.editor.execCommand( 'paste', '<a href="x">x</a>' );
wait();
} );
}
} );
@@ -0,0 +1,23 @@
<p>Test URLs</p>

<ul>
<li><input type="text" value="https://twitter.com/reinmarpl/status/573118615274315776"></li>
<li><input type="text" value="http://i.imgur.com/Z3ilPBI.jpg"></li>
</ul>

<textarea id="editor1" cols="10" rows="10">
<p>Paste the URL here: ^</p>
<p>Copy and paste me once undone!</p>
</textarea>

<script>
embedTools.delayJsonp();
CKEDITOR.replace( 'editor1', {
removePlugins: 'embedsemantic',
extraPlugins: 'embed',
height: 500,
// Make them narrow so images don't take too much space.
width: 600
} );
</script>
@@ -0,0 +1,12 @@
@bender-tags: tc, 4.5.2, 13532
@bender-include: ../../embedbase/_helpers/tools.js
@bender-ui: collapsed
@bender-ckeditor-plugins: wysiwygarea,sourcearea,htmlwriter,entities,toolbar,elementspath,undo,clipboard,format,basicstyles,autolink,autoembed,link
1. Copy an URL.
1. Paste it. The link becomes a widget.
1. Undo.
1. Select some text **in the editor**.
1. Copy it.
1. Paste it.
1. The text should be pasted. The link, which once was embedded (but undone) **should remain a link**.

0 comments on commit 0d71fa2

Please sign in to comment.
You can’t perform that action at this time.