Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix for cutting in Safari when selecting all with widget at the beginning #3609

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions plugins/widget/plugin.js
Original file line number Diff line number Diff line change
Expand Up @@ -3426,6 +3426,11 @@
if ( focused ) {
editor.widgets.del( focused );
} else {
// We have to add fillers manually for Safari (#3537).
if ( CKEDITOR.env.webkit && !CKEDITOR.env.chrome ) {
CKEDITOR.plugins.widgetselection.addFillers( editor.editable() );
}

editor.extractSelectedHtml();
}

Expand Down
32 changes: 32 additions & 0 deletions tests/plugins/widget/manual/clipboardhtmlselectallsafari.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
<div id="editor">
<div data-widget="customwidget">Widget</div>
<p>Adipisicing corporis rem repellendus vel mollitia vero? Consectetur dolores voluptatibus illo ipsam eveniet? Lorem ipsum dolor sit amet.</p>
</div>


<script>
// No console support on mobiles (without connecting to another device).
if ( bender.tools.env.mobile || !CKEDITOR.env.safari ) {
bender.ignore();
}

CKEDITOR.replace( 'editor', {
extraAllowedContent: 'span',
extraPlugins: 'customwidget',
allowedContent: true
} );

CKEDITOR.plugins.add( 'customwidget', {
requires: 'widget',
allowedContent: 'div',

init: function ( editor ) {
var counter = 0;

editor.widgets.add( 'customwidget', {
button: 'Add widget',
template: '<div>Widget</div>'
} );
}
} );
</script>
14 changes: 14 additions & 0 deletions tests/plugins/widget/manual/clipboardhtmlselectallsafari.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
@bender-tags: 4.13.1, bug, 3537
@bender-ui: collapsed
@bender-ckeditor-plugins: widget, undo, wysiwygarea, toolbar

1. Select all.
2. Cut.

## Expected

Content is removed from the editor.

## Unexpected

Content remains inside the editor.
25 changes: 25 additions & 0 deletions tests/plugins/widget/widgetsintegration.js
Original file line number Diff line number Diff line change
Expand Up @@ -1175,6 +1175,31 @@
}
} ),

// (#3537)
'test content is removed after cutting (widget at the beginning)': createCopyCutTest( {
event: 'cut',
html: '<div id="w1" data-widget="test3">test3</div>' +
'<p>Ipsum</p>',

init: function( editor ) {
var range = editor.createRange(),
editable = editor.editable();

range.selectNodeContents( editable );
range.select();

// We must simulate widgetselection behaviour.
CKEDITOR.plugins.widgetselection.addFillers( editable );
},

assert: function( editor ) {
var data = editor.getData();

assert.isNotMatching( /<div.+?>/, data, 'widgets are removed' );
assert.isTrue( editor.getSelection().isCollapsed(), 'selection is collapsed' );
}
} ),

// (#3138)
'test undo stack after copying (multiple widgets)': createCopyCutTest( {
event: 'copy',
Expand Down