8
0
Просмотр исходного кода

Disabled pasting content when editor is readonly.

Oskar Wróbel 8 лет назад
Родитель
Сommit
72d908bbb5

+ 6 - 0
packages/ckeditor5-clipboard/src/clipboard.js

@@ -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 = '';
 

+ 14 - 0
packages/ckeditor5-clipboard/tests/clipboard.js

@@ -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.