Kaynağa Gözat

Prevent shiftenter to copy attribtues without copyOnEnter flag.

Mateusz Samsel 6 yıl önce
ebeveyn
işleme
c52e5d7a91

+ 2 - 0
packages/ckeditor5-enter/src/shiftentercommand.js

@@ -84,6 +84,8 @@ function softBreakAction( model, writer, selection ) {
 	if ( isSelectionEmpty ) {
 		const attributesToCopy = getCopyOnEnterAttributes( model.schema, selection.getAttributes() );
 		insertBreak( writer, range.end );
+		// transforms: [ [ key1, value1 ], ... ] => [ key1, ... ]
+		writer.removeSelectionAttribute( Array.from( selection.getAttributes() ).map( x => x[ 0 ] ) );
 		writer.setSelectionAttribute( attributesToCopy );
 	} else {
 		const leaveUnmerged = !( range.start.isAtStart && range.end.isAtEnd );

+ 25 - 0
packages/ckeditor5-enter/tests/shiftentercommand.js

@@ -101,6 +101,31 @@ describe( 'ShiftEnterCommand', () => {
 				'<p>x</p><p>[]foo</p><p>y</p>',
 				'<p>x</p><p><softBreak></softBreak>[]foo</p><p>y</p>'
 			);
+
+			describe( 'copyOnEnter', () => {
+				beforeEach( () => {
+					schema.extend( '$text', { allowAttributes: [ 'foo', 'bar' ] } );
+					schema.setAttributeProperties( 'foo', { copyOnEnter: true } );
+				} );
+
+				test(
+					'allowed attributes are copied',
+					'<p><$text foo="true">test[]</$text></p>',
+					'<p><$text foo="true">test</$text><softBreak></softBreak><$text foo="true">[]</$text></p>'
+				);
+
+				test(
+					'unknown attributes are not copied',
+					'<p><$text bar="true">test[]</$text></p>',
+					'<p><$text bar="true">test</$text><softBreak></softBreak>[]</p>'
+				);
+
+				test(
+					'only allowed attributes are copied from mix set',
+					'<p><$text bar="true" foo="true">test[]</$text></p>',
+					'<p><$text bar="true" foo="true">test</$text><softBreak></softBreak><$text foo="true">[]</$text></p>'
+				);
+			} );
 		} );
 
 		describe( 'non-collapsed selection', () => {