Skip to content
This repository has been archived by the owner on Jun 26, 2020. It is now read-only.

Commit

Permalink
Merge f51c35c into ae4ea85
Browse files Browse the repository at this point in the history
  • Loading branch information
oskarwrobel committed Jun 4, 2018
2 parents ae4ea85 + f51c35c commit 0030ac8
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 4 deletions.
10 changes: 6 additions & 4 deletions src/clipboard.js
Original file line number Diff line number Diff line change
Expand Up @@ -134,13 +134,15 @@ export default class Clipboard extends Plugin {

// The clipboard paste pipeline.

this.listenTo( viewDocument, 'clipboardInput', ( evt, data ) => {
// Pasting and dropping is disabled when editor is read-only.
// See: https://github.com/ckeditor/ckeditor5-clipboard/issues/26.
// Pasting and dropping is disabled when editor is read-only.
// See: https://github.com/ckeditor/ckeditor5-clipboard/issues/26.
this.listenTo( viewDocument, 'clipboardInput', evt => {
if ( editor.isReadOnly ) {
return;
evt.stop();
}
}, { priority: 'highest' } );

this.listenTo( viewDocument, 'clipboardInput', ( evt, data ) => {
const dataTransfer = data.dataTransfer;
let content = '';

Expand Down
23 changes: 23 additions & 0 deletions tests/clipboard.js
Original file line number Diff line number Diff line change
Expand Up @@ -194,6 +194,29 @@ describe( 'Clipboard feature', () => {
sinon.assert.notCalled( spy );
} );

it( 'stops `clipboardInput` event on highest priority when editor is read-only', () => {
const dataTransferMock = createDataTransfer( { 'text/html': '<p>x</p>', 'text/plain': 'y' } );
const spy = sinon.spy();

viewDocument.on( 'clipboardInput', spy, { priority: 'high' } );

editor.isReadOnly = true;

viewDocument.fire( 'clipboardInput', {
dataTransfer: dataTransferMock
} );

sinon.assert.notCalled( spy );

editor.isReadOnly = false;

viewDocument.fire( 'clipboardInput', {
dataTransfer: dataTransferMock
} );

sinon.assert.calledOnce( spy );
} );

it( 'does not insert content if the whole content was invalid', () => {
// Whole content is invalid. Even though there is "view" content, the "model" content would be empty.
// Do not insert content in this case.
Expand Down

0 comments on commit 0030ac8

Please sign in to comment.