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

Commit

Permalink
Merge pull request #47 from ckeditor/t/ckeditor5-image/208
Browse files Browse the repository at this point in the history
Fix: Disabled the entire clipboard input pipeline when the editor is read-only. Closes #48.
  • Loading branch information
Reinmar authored Jun 4, 2018
2 parents ae4ea85 + e0cfac5 commit b40ec4b
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 b40ec4b

Please sign in to comment.