Skip to content

Commit 48311f8

Browse files
committed
Merge branch 't/13872'
2 parents 0f7494b + eb8a56c commit 48311f8

File tree

5 files changed

+110
-2
lines changed

5 files changed

+110
-2
lines changed

CHANGES.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ Fixed Issues:
1212
* [#13887](https://dev.ckeditor.com/ticket/13887): Fixed: Link target now supports wider ASCII character range. Thanks to [SamZiemer](https://github.com/SamZiemer)!
1313
* [#13790](https://dev.ckeditor.com/ticket/13790): Fixed: Allow for the iframe having been removed already. Thanks to [Stefan Rijnhart](https://github.com/StefanRijnhart)!
1414
* [#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)!
15+
* [#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.
1516
* [#13879](http://dev.ckeditor.com/ticket/13879): Fixed: Preventing [`editor.drop`](http://docs.ckeditor.com/#!/api/CKEDITOR.editor-event-drop) event.
1617
* [#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.
1718
* [#12189](http://dev.ckeditor.com/ticket/12189): Fixed: Link plugin dialog does not display subject of email links if subject parameter is not lowercase.

plugins/clipboard/plugin.js

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -525,7 +525,10 @@
525525

526526
if ( CKEDITOR.plugins.clipboard.isCustomCopyCutSupported ) {
527527
var initOnCopyCut = function( evt ) {
528-
clipboard.initPasteDataTransfer( evt, editor );
528+
// If user tries to cut in read-only editor, we must prevent default action. (#13872)
529+
if ( !editor.readOnly || evt.name != 'cut' ) {
530+
clipboard.initPasteDataTransfer( evt, editor );
531+
}
529532
evt.data.preventDefault();
530533
};
531534

@@ -534,7 +537,10 @@
534537

535538
// Delete content with the low priority so one can overwrite cut data.
536539
editable.on( 'cut', function() {
537-
editor.extractSelectedHtml();
540+
// If user tries to cut in read-only editor, we must prevent default action. (#13872)
541+
if ( !editor.readOnly ) {
542+
editor.extractSelectedHtml();
543+
}
538544
}, null, null, 999 );
539545
}
540546

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
<body>
2+
<div>
3+
<textarea></textarea>
4+
</div>
5+
<div id="classic">
6+
<p>Example text</p>
7+
</div>
8+
9+
<div id="inline">
10+
<p>Example text</p>
11+
</div>
12+
13+
<script>
14+
CKEDITOR.replace( 'classic', { readOnly: true } );
15+
CKEDITOR.inline( 'inline', { readOnly: true } );
16+
</script>
17+
</body>
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
@bender-tags: tc, 4.5.5, 13782, editor
2+
@bender-ui: collapsed
3+
@bender-ckeditor-plugins: wysiwygarea, clipboard, toolbar, floatingspace
4+
5+
----
6+
7+
1. Select some text in the first editor.
8+
2. Press `CTRL + X`.
9+
3. Try to paste into the textarea above the editors.
10+
11+
**Expected:**
12+
* Text shouldn't be removed from editor.
13+
* Text selected in the editor shouldn't be pasted into the textarea.
14+
15+
----
16+
17+
1. Select some text in the second editor.
18+
2. Press `CTRL + X`.
19+
3. Try to paste into the textarea above the editors.
20+
21+
**Expected:**
22+
* Text shouldn't be removed from editor.
23+
* Text selected in the editor shouldn't be pasted into the textarea.

tests/plugins/clipboard/readonly.js

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
/* bender-tags: editor, clipboard, 13872 */
2+
/* bender-ckeditor-plugins: toolbar, clipboard */
3+
4+
'use strict';
5+
6+
bender.editors = {
7+
classic: {
8+
config: {
9+
readOnly: true
10+
}
11+
},
12+
classic_editable: {},
13+
inline: {
14+
creator: 'inline',
15+
config: {
16+
readOnly: true
17+
}
18+
},
19+
inline_editable: {
20+
creator: 'inline'
21+
}
22+
};
23+
24+
var tests = {
25+
setUp: function() {
26+
// The native handling of copy/cut doesn't have such problems.
27+
if ( !CKEDITOR.plugins.clipboard.isCustomCopyCutSupported ) {
28+
assert.ignore();
29+
}
30+
31+
this.initPasteSpy = sinon.spy( CKEDITOR.plugins.clipboard, 'initPasteDataTransfer' );
32+
},
33+
34+
tearDown: function() {
35+
this.initPasteSpy.restore();
36+
},
37+
38+
'test if cut is prevented depending on read-only mode': function( editor, bot ) {
39+
var content = '<p>[Some] text</p>',
40+
expected = editor.readOnly ? content : '<p>^ text</p>';
41+
42+
bot.setHtmlWithSelection( content );
43+
44+
editor.editable().fire( 'cut', new CKEDITOR.dom.event( {} ) );
45+
46+
assert.areSame( expected, bot.htmlWithSelection() );
47+
assert.areSame( !editor.readOnly, CKEDITOR.plugins.clipboard.initPasteDataTransfer.called, 'initPasteDataTransfer call' );
48+
},
49+
50+
'test copy depending on read-only mode': function( editor, bot ) {
51+
bot.setHtmlWithSelection( '<p>[Some] text</p>' );
52+
53+
editor.editable().fire( 'copy', new CKEDITOR.dom.event( {} ) );
54+
55+
assert.areSame( true, CKEDITOR.plugins.clipboard.initPasteDataTransfer.called, 'initPasteDataTransfer call' );
56+
}
57+
};
58+
59+
tests = bender.tools.createTestsForEditors( CKEDITOR.tools.objectKeys( bender.editors ), tests );
60+
61+
bender.test( tests );

0 commit comments

Comments
 (0)