瀏覽代碼

Allow pasting only text inside restricted editing exception.

Maciej Gołaszewski 6 年之前
父節點
當前提交
26ba68762d

+ 5 - 0
packages/ckeditor5-restricted-editing/src/restrictededitingmodeediting.js

@@ -96,6 +96,11 @@ export default class RestrictedEditingModeEditing extends Plugin {
 
 		const allowedAttributes = editor.config.get( 'restrictedEditing.allowedAttributes' );
 		editor.model.schema.addAttributeCheck( ( context, attributeName ) => allowedAttributes.includes( attributeName ) );
+		editor.model.schema.addChildCheck( ( context, childDefinition ) => {
+			if ( Array.from( context.getNames() ).includes( '$clipboardHolder' ) ) {
+				return childDefinition.name === '$text';
+			}
+		} );
 
 		this.listenTo( viewDoc, 'clipboardOutput', ( evt, data ) => {
 			if ( data.method == 'cut' ) {

+ 17 - 1
packages/ckeditor5-restricted-editing/tests/restrictededitingmodeediting.js

@@ -19,6 +19,7 @@ import Clipboard from '@ckeditor/ckeditor5-clipboard/src/clipboard';
 import RestrictedEditingModeEditing from './../src/restrictededitingmodeediting';
 import RestrictedEditingModeNavigationCommand from '../src/restrictededitingmodenavigationcommand';
 import ItalicEditing from '@ckeditor/ckeditor5-basic-styles/src/italic/italicediting';
+import BlockQuoteEditing from '@ckeditor/ckeditor5-block-quote/src/blockquoteediting';
 
 describe( 'RestrictedEditingModeEditing', () => {
 	let editor, model;
@@ -590,7 +591,9 @@ describe( 'RestrictedEditingModeEditing', () => {
 
 		beforeEach( async () => {
 			editor = await VirtualTestEditor.create( {
-				plugins: [ Paragraph, BoldEditing, ItalicEditing, StrikethroughEditing, Typing, Clipboard, RestrictedEditingModeEditing ]
+				plugins: [ Paragraph, BoldEditing, ItalicEditing, StrikethroughEditing, BlockQuoteEditing, Typing, Clipboard,
+					RestrictedEditingModeEditing
+				]
 			} );
 			model = editor.model;
 			viewDoc = editor.editing.view.document;
@@ -834,6 +837,19 @@ describe( 'RestrictedEditingModeEditing', () => {
 					);
 					assertMarkerRangePaths( [ 0, 4 ], [ 0, 10 ] );
 				} );
+
+				it( 'should not allow pasting block elements other then paragraph', () => {
+					setModelData( model, '<paragraph>foo b[]ar baz</paragraph>' );
+					const firstParagraph = model.document.getRoot().getChild( 0 );
+					addExceptionMarker( 4, 7, firstParagraph );
+
+					viewDoc.fire( 'clipboardInput', {
+						dataTransfer: createDataTransfer( { 'text/html': '<blockquote><p>XXX</p></blockquote>', 'text/plain': 'XXX' } )
+					} );
+
+					assertEqualMarkup( getModelData( model ), '<paragraph>foo bXXX[]ar baz</paragraph>' );
+					assertMarkerRangePaths( [ 0, 4 ], [ 0, 10 ] );
+				} );
 			} );
 
 			describe( 'non-collapsed selection', () => {