Skip to content

Commit bca0002

Browse files
committed
Merge branch 't/13186' into major
2 parents 7dd063e + 3e945b1 commit bca0002

File tree

3 files changed

+68
-1
lines changed

3 files changed

+68
-1
lines changed

CHANGES.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ Fixed Issues:
1818
* [#13300](http://dev.ckeditor.com/ticket/13300): Fixed: The `internalCommit` argument in the image dialog seems to be never used.
1919
* [#13036](http://dev.ckeditor.com/ticket/13036): Fixed: Notifications are 10px more to the right.
2020
* [#13280](http://dev.ckeditor.com/ticket/13280): [IE8] Fixed: Undo after inline widget drag&drop throws an error.
21+
* [#13186](http://dev.ckeditor.com/ticket/13186): Fixed: Content dropped to a nested editable is not filtered by the Advanced Content Filter.
2122
* Toolbar configurators:
2223
* [#13185](http://dev.ckeditor.com/ticket/13185): Fixed: Wrong position of the suggestion box if there is not enough space below the caret.
2324
* [#13138](http://dev.ckeditor.com/ticket/13138): Fixed: The "Toggle empty elements" button label is unclear.

plugins/widget/plugin.js

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2706,7 +2706,28 @@
27062706

27072707
// Handle pasted single widget.
27082708
editor.on( 'paste', function( evt ) {
2709-
evt.data.dataValue = evt.data.dataValue.replace( pasteReplaceRegex, pasteReplaceFn );
2709+
var data = evt.data;
2710+
2711+
data.dataValue = data.dataValue.replace( pasteReplaceRegex, pasteReplaceFn );
2712+
2713+
// If drag'n'drop kind of paste into nested editable (data.range), selection is set AFTER
2714+
// data is pasted, which means editor has no chance to change activeFilter's context.
2715+
// As a result, pasted data is filtered with default editor's filter instead of NE's and
2716+
// funny things get inserted. Changing the filter by analysis of the paste range below (#13186).
2717+
if ( data.range ) {
2718+
// Check if pasting into nested editable.
2719+
var nestedEditable = Widget.getNestedEditable( editor.editable(), data.range.startContainer );
2720+
2721+
if ( nestedEditable ) {
2722+
// Retrieve the filter from NE's data and set it active before editor.insertHtml is done
2723+
// in clipboard plugin.
2724+
var filter = CKEDITOR.filter.instances[ nestedEditable.data( 'cke-filter' ) ];
2725+
2726+
if ( filter ) {
2727+
editor.setActiveFilter( filter );
2728+
}
2729+
}
2730+
}
27102731
} );
27112732

27122733
// Listen with high priority to check widgets after data was inserted.

tests/plugins/widget/nestededitables.js

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,10 @@
99
bender.editor = {
1010
config: {
1111
allowedContent: true,
12+
13+
// (#13186)
14+
pasteFilter: null,
15+
1216
on: {
1317
instanceReady: function( evt ) {
1418
evt.editor.dataProcessor.writer.sortAttributes = 1;
@@ -1151,6 +1155,47 @@
11511155
} );
11521156
},
11531157

1158+
// (#13186)
1159+
'test pasting into widget nested editable when range in paste data (drop)': function() {
1160+
var editor = this.editor,
1161+
bot = this.editorBot;
1162+
1163+
editor.widgets.add( 'widget1', {
1164+
editables: {
1165+
nested: {
1166+
selector: '#widget1-nested',
1167+
allowedContent: 'i(a,c){color}'
1168+
}
1169+
}
1170+
} );
1171+
1172+
bot.setData( '<p>foo</p><div id="w1" data-widget="widget1"><p id="widget1-nested">xx</p></div>', function() {
1173+
var widget = getWidgetById( editor, 'w1' ),
1174+
nested = widget.editables.nested,
1175+
range = editor.createRange();
1176+
1177+
range.setStart( nested.getFirst(), 1 );
1178+
range.collapse( 1 );
1179+
1180+
editor.once( 'afterPaste', function() {
1181+
resume( function() {
1182+
assert.isInnerHtmlMatching( 'xy<i class="a c" style="color:green">z</i>yx@', nested.getHtml(), {
1183+
fixStyles: true
1184+
}, 'Nested editable filter in use.' );
1185+
} );
1186+
} );
1187+
1188+
editor.fire( 'paste', {
1189+
type: 'auto',
1190+
dataValue: 'y<i class="a b c d" style="margin-left:20px; color:green">z</i>y',
1191+
method: 'drop',
1192+
range: range
1193+
} );
1194+
1195+
wait();
1196+
} );
1197+
},
1198+
11541199
// Behaviour has been changed in 4.5 (#12112), so we're leaving this
11551200
// test as a validation of this change.
11561201
'test widgets\' commands are enabled in nested editable': function() {

0 commit comments

Comments
 (0)