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

Commit

Permalink
Disabled pasting content when editor is readonly.
Browse files Browse the repository at this point in the history
  • Loading branch information
oskarwrobel committed Jul 14, 2017
1 parent 3980f2c commit cfe56cc
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 0 deletions.
6 changes: 6 additions & 0 deletions src/clipboard.js
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,12 @@ export default class Clipboard extends Plugin {
// The clipboard paste pipeline.

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

const dataTransfer = data.dataTransfer;
let content = '';

Expand Down
14 changes: 14 additions & 0 deletions tests/clipboard.js
Original file line number Diff line number Diff line change
Expand Up @@ -174,6 +174,20 @@ describe( 'Clipboard feature', () => {
expect( stringifyModel( spy.args[ 0 ][ 0 ] ) ).to.equal( '<paragraph>x</paragraph>' );
} );

it( 'do not insert content when editor is read-only', () => {
const dataTransferMock = createDataTransfer( { 'text/html': '<p>x</p>', 'text/plain': 'y' } );
const spy = sinon.stub( editor.data, 'insertContent' );

editor.isReadOnly = true;

editingView.fire( 'paste', {
dataTransfer: dataTransferMock,
preventDefault() {}
} );

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

it( 'converts content in an "all allowed" context', () => {
// It's enough if we check this here with a text node and paragraph because if the conversion was made
// in a normal root, then text or paragraph wouldn't be allowed here.
Expand Down

0 comments on commit cfe56cc

Please sign in to comment.