Skip to content

Commit

Permalink
Merge pull request #890 from ckeditor/t/869
Browse files Browse the repository at this point in the history
Fixing bug which cleared clipboard when collapsed selection was copied
  • Loading branch information
Comandeer authored Jan 15, 2018
2 parents bc59351 + 1cf2355 commit 59c8722
Show file tree
Hide file tree
Showing 5 changed files with 55 additions and 1 deletion.
4 changes: 4 additions & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@ New Features:

* [#1338](https://github.com/ckeditor/ckeditor-dev/issues/1338): Keystroke labels are displayed for function keys (like F7, F8).

Fixed Issues:

* [#869](https://github.com/ckeditor/ckeditor-dev/issues/869): Fixed: Empty selection clears cached clipboard data in editor.

## CKEditor 4.8.1

New Features:
Expand Down
7 changes: 6 additions & 1 deletion plugins/clipboard/plugin.js
Original file line number Diff line number Diff line change
Expand Up @@ -510,7 +510,12 @@

if ( CKEDITOR.plugins.clipboard.isCustomCopyCutSupported ) {
var initOnCopyCut = function( evt ) {
// If user tries to cut in read-only editor, we must prevent default action. (https://dev.ckeditor.com/ticket/13872)
// There shouldn't be anything to copy/cut when selection is collapsed (#869).
if ( editor.getSelection().isCollapsed() ) {
return;
}

// If user tries to cut in read-only editor, we must prevent default action (https://dev.ckeditor.com/ticket/13872).
if ( !editor.readOnly || evt.name != 'cut' ) {
clipboard.initPasteDataTransfer( evt, editor );
}
Expand Down
23 changes: 23 additions & 0 deletions tests/plugins/clipboard/clipboard.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,5 +23,28 @@ bender.test( {
} );

editor.execCommand( 'cut' );
},

// #869
'test check if collapse selection is not copied': function() {
if ( !CKEDITOR.plugins.clipboard.isCustomCopyCutSupported ) {
assert.ignore();
}

var editor = this.editor,
bot = this.editorBot,
range;

bot.setHtmlWithSelection( '<p>[Some] text</p>' );

editor.editable().fire( 'copy', new CKEDITOR.dom.event( {} ) );
assert.areSame( 'Some', CKEDITOR.plugins.clipboard.copyCutData.getData( 'text/html' ) );

range = editor.getSelection().getRanges()[ 0 ];
range.collapse();
range.select();

editor.editable().fire( 'copy', new CKEDITOR.dom.event( {} ) );
assert.areSame( 'Some', CKEDITOR.plugins.clipboard.copyCutData.getData( 'text/html' ) );
}
} );
6 changes: 6 additions & 0 deletions tests/plugins/clipboard/manual/dontcopyemptyselection.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
<textarea name="editor" id="editor" cols="30" rows="10">
<p>Hello world</p>
</textarea>
<script>
CKEDITOR.replace( 'editor' );
</script>
16 changes: 16 additions & 0 deletions tests/plugins/clipboard/manual/dontcopyemptyselection.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
@bender-ui: collapsed
@bender-tags: 4.9.0, bug, 869
@bender-ckeditor-plugins: wysiwygarea, toolbar, clipboard

----

1. Select some text in editor.
1. Copy text with shortcut `Ctrl/Cmd + C`.
1. Paste text in editor.
1. Now make collapsed selection.
1. Copy this collapsed selection with shortcut `Ctrl/Cmd + C`.
1. Paste text in editor.

**Expected:** Previously selected text is paste in editor.

**Unexpected:** There is nothing pasted in editor.

0 comments on commit 59c8722

Please sign in to comment.