Jelajahi Sumber

Merge branch 't/ckeditor5/436' into i/5668

Aleksander Nowodzinski 6 tahun lalu
induk
melakukan
7e97588c9a

+ 5 - 1
packages/ckeditor5-code-block/src/codeblockediting.js

@@ -179,7 +179,11 @@ export default class CodeBlockEditing extends Plugin {
 
 
 				// "f[oo]"                          ->   <$text code="true">oo</text>
 				// "f[oo]"                          ->   <$text code="true">oo</text>
 				else {
 				else {
-					writer.setAttribute( 'code', true, docFragment.getChild( 0 ) );
+					const textNode = docFragment.getChild( 0 );
+
+					if ( schema.checkAttribute( textNode, 'code' ) ) {
+						writer.setAttribute( 'code', true, textNode );
+					}
 				}
 				}
 			} );
 			} );
 		} );
 		} );

+ 14 - 0
packages/ckeditor5-code-block/tests/codeblockediting.js

@@ -986,6 +986,10 @@ describe( 'CodeBlockEditing', () => {
 			} );
 			} );
 
 
 			it( 'should wrap a partial single-line selection into an inline code (#1)', () => {
 			it( 'should wrap a partial single-line selection into an inline code (#1)', () => {
+				model.schema.extend( '$text', {
+					allowAttributes: 'code'
+				} );
+
 				setModelData( model, '<codeBlock language="css">[fo]o<softBreak></softBreak>bar</codeBlock>' );
 				setModelData( model, '<codeBlock language="css">[fo]o<softBreak></softBreak>bar</codeBlock>' );
 
 
 				expect( stringify( model.getSelectedContent( model.document.selection ) ) ).to.equal(
 				expect( stringify( model.getSelectedContent( model.document.selection ) ) ).to.equal(
@@ -994,6 +998,10 @@ describe( 'CodeBlockEditing', () => {
 			} );
 			} );
 
 
 			it( 'should wrap a partial single-line selection into an inline code (#2)', () => {
 			it( 'should wrap a partial single-line selection into an inline code (#2)', () => {
+				model.schema.extend( '$text', {
+					allowAttributes: 'code'
+				} );
+
 				setModelData( model, '<codeBlock language="css">foo<softBreak></softBreak>b[a]r</codeBlock>' );
 				setModelData( model, '<codeBlock language="css">foo<softBreak></softBreak>b[a]r</codeBlock>' );
 
 
 				expect( stringify( model.getSelectedContent( model.document.selection ) ) ).to.equal(
 				expect( stringify( model.getSelectedContent( model.document.selection ) ) ).to.equal(
@@ -1001,6 +1009,12 @@ describe( 'CodeBlockEditing', () => {
 				);
 				);
 			} );
 			} );
 
 
+			it( 'should now wrap a partial single-line selection into an inline code when the attribute is disallowed', () => {
+				setModelData( model, '<codeBlock language="css">foo<softBreak></softBreak>b[a]r</codeBlock>' );
+
+				expect( stringify( model.getSelectedContent( model.document.selection ) ) ).to.equal( 'a' );
+			} );
+
 			it( 'should preserve a code block in a cross-selection (#1)', () => {
 			it( 'should preserve a code block in a cross-selection (#1)', () => {
 				setModelData( model, '<paragraph>[x</paragraph><codeBlock language="css">fo]o<softBreak></softBreak>bar</codeBlock>' );
 				setModelData( model, '<paragraph>[x</paragraph><codeBlock language="css">fo]o<softBreak></softBreak>bar</codeBlock>' );