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

Commit

Permalink
Disabled cutting content when editor is readolny.
Browse files Browse the repository at this point in the history
  • Loading branch information
oskarwrobel committed Jul 14, 2017
1 parent cfe56cc commit 7062474
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 1 deletion.
10 changes: 9 additions & 1 deletion src/clipboard.js
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,15 @@ export default class Clipboard extends Plugin {
}

this.listenTo( editingView, 'copy', onCopyCut, { priority: 'low' } );
this.listenTo( editingView, 'cut', onCopyCut, { priority: 'low' } );
this.listenTo( editingView, 'cut', ( evt, data ) => {
// Cutting is disabled when editor is read-only.
// See: https://github.com/ckeditor/ckeditor5-clipboard/issues/26.
if ( editor.isReadOnly ) {
data.preventDefault();
} else {
onCopyCut( evt, data );
}
}, { priority: 'low' } );

this.listenTo( editingView, 'clipboardOutput', ( evt, data ) => {
if ( !data.content.isEmpty ) {
Expand Down
19 changes: 19 additions & 0 deletions tests/clipboard.js
Original file line number Diff line number Diff line change
Expand Up @@ -283,6 +283,25 @@ describe( 'Clipboard feature', () => {
} );
} );

it( 'not fires clipboardOutput and preventDefault event for cut when editor is read-only', () => {
const dataTransferMock = createDataTransfer();
const preventDefaultSpy = sinon.spy();
const spy = sinon.spy();

setModelData( editor.document, '<paragraph>a[bc</paragraph><paragraph>de]f</paragraph>' );
editor.isReadOnly = true;

editingView.on( 'clipboardOutput', spy );

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

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

it( 'uses low priority observer for the copy event', () => {
const dataTransferMock = createDataTransfer();
const spy = sinon.spy();
Expand Down

0 comments on commit 7062474

Please sign in to comment.