diff --git a/CHANGES.md b/CHANGES.md index a3514c5453c..024c5a0ae02 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -12,6 +12,7 @@ Fixed Issues: * [#13887](https://dev.ckeditor.com/ticket/13887): Fixed: Link target now supports wider ASCII character range. Thanks to [SamZiemer](https://github.com/SamZiemer)! * [#13790](https://dev.ckeditor.com/ticket/13790): Fixed: Allow for the iframe having been removed already. Thanks to [Stefan Rijnhart](https://github.com/StefanRijnhart)! * [#13803](https://dev.ckeditor.com/ticket/13803): Fixed: Allow the editor to be destroyed before being fully initialized. Thanks to [Cyril Fluck](https://github.com/cyril-sf)! +* [#13872](http://dev.ckeditor.com/ticket/13872): Fixed: Cut is no longer possible in [read-only](http://docs.ckeditor.com/#!/api/CKEDITOR.editor-property-readOnly) mode. * [#13879](http://dev.ckeditor.com/ticket/13879): Fixed: Preventing [`editor.drop`](http://docs.ckeditor.com/#!/api/CKEDITOR.editor-event-drop) event. * [#12848](http://dev.ckeditor.com/ticket/12848): Fixed: Opening find dialog in [read-only](http://docs.ckeditor.com/#!/api/CKEDITOR.editor-property-readOnly) mode will no longer throw an exception. * [#12189](http://dev.ckeditor.com/ticket/12189): Fixed: Link plugin dialog does not display subject of email links if subject parameter is not lowercase. diff --git a/plugins/clipboard/plugin.js b/plugins/clipboard/plugin.js index 03578396df4..65a8774e987 100644 --- a/plugins/clipboard/plugin.js +++ b/plugins/clipboard/plugin.js @@ -525,7 +525,10 @@ if ( CKEDITOR.plugins.clipboard.isCustomCopyCutSupported ) { var initOnCopyCut = function( evt ) { - clipboard.initPasteDataTransfer( evt, editor ); + // If user tries to cut in read-only editor, we must prevent default action. (#13872) + if ( !editor.readOnly || evt.name != 'cut' ) { + clipboard.initPasteDataTransfer( evt, editor ); + } evt.data.preventDefault(); }; @@ -534,7 +537,10 @@ // Delete content with the low priority so one can overwrite cut data. editable.on( 'cut', function() { - editor.extractSelectedHtml(); + // If user tries to cut in read-only editor, we must prevent default action. (#13872) + if ( !editor.readOnly ) { + editor.extractSelectedHtml(); + } }, null, null, 999 ); } diff --git a/tests/plugins/clipboard/manual/readonlycut.html b/tests/plugins/clipboard/manual/readonlycut.html new file mode 100644 index 00000000000..5c84506c051 --- /dev/null +++ b/tests/plugins/clipboard/manual/readonlycut.html @@ -0,0 +1,17 @@ + +
+ +
+
+

Example text

+
+ +
+

Example text

+
+ + + diff --git a/tests/plugins/clipboard/manual/readonlycut.md b/tests/plugins/clipboard/manual/readonlycut.md new file mode 100644 index 00000000000..8c12b5681bc --- /dev/null +++ b/tests/plugins/clipboard/manual/readonlycut.md @@ -0,0 +1,23 @@ +@bender-tags: tc, 4.5.5, 13782, editor +@bender-ui: collapsed +@bender-ckeditor-plugins: wysiwygarea, clipboard, toolbar, floatingspace + +---- + +1. Select some text in the first editor. +2. Press `CTRL + X`. +3. Try to paste into the textarea above the editors. + +**Expected:** +* Text shouldn't be removed from editor. +* Text selected in the editor shouldn't be pasted into the textarea. + +---- + +1. Select some text in the second editor. +2. Press `CTRL + X`. +3. Try to paste into the textarea above the editors. + +**Expected:** +* Text shouldn't be removed from editor. +* Text selected in the editor shouldn't be pasted into the textarea. diff --git a/tests/plugins/clipboard/readonly.js b/tests/plugins/clipboard/readonly.js new file mode 100644 index 00000000000..01ff498c874 --- /dev/null +++ b/tests/plugins/clipboard/readonly.js @@ -0,0 +1,61 @@ +/* bender-tags: editor, clipboard, 13872 */ +/* bender-ckeditor-plugins: toolbar, clipboard */ + +'use strict'; + +bender.editors = { + classic: { + config: { + readOnly: true + } + }, + classic_editable: {}, + inline: { + creator: 'inline', + config: { + readOnly: true + } + }, + inline_editable: { + creator: 'inline' + } +}; + +var tests = { + setUp: function() { + // The native handling of copy/cut doesn't have such problems. + if ( !CKEDITOR.plugins.clipboard.isCustomCopyCutSupported ) { + assert.ignore(); + } + + this.initPasteSpy = sinon.spy( CKEDITOR.plugins.clipboard, 'initPasteDataTransfer' ); + }, + + tearDown: function() { + this.initPasteSpy.restore(); + }, + + 'test if cut is prevented depending on read-only mode': function( editor, bot ) { + var content = '

[Some] text

', + expected = editor.readOnly ? content : '

^ text

'; + + bot.setHtmlWithSelection( content ); + + editor.editable().fire( 'cut', new CKEDITOR.dom.event( {} ) ); + + assert.areSame( expected, bot.htmlWithSelection() ); + assert.areSame( !editor.readOnly, CKEDITOR.plugins.clipboard.initPasteDataTransfer.called, 'initPasteDataTransfer call' ); + }, + + 'test copy depending on read-only mode': function( editor, bot ) { + bot.setHtmlWithSelection( '

[Some] text

' ); + + editor.editable().fire( 'copy', new CKEDITOR.dom.event( {} ) ); + + assert.areSame( true, CKEDITOR.plugins.clipboard.initPasteDataTransfer.called, 'initPasteDataTransfer call' ); + } +}; + +tests = bender.tools.createTestsForEditors( CKEDITOR.tools.objectKeys( bender.editors ), tests ); + +bender.test( tests );