Selaa lähdekoodia

We should check selection attribues instead of text attrs.

Kamil Piechaczek 7 vuotta sitten
vanhempi
commit
5da55c3c0e

+ 2 - 1
packages/ckeditor5-engine/src/model/schema.js

@@ -14,6 +14,7 @@ import mix from '@ckeditor/ckeditor5-utils/src/mix';
 import Range from './range';
 import Position from './position';
 import Element from './element';
+import Text from './text';
 import TreeWalker from './treewalker';
 
 /**
@@ -491,7 +492,7 @@ export default class Schema {
 			const firstPosition = selection.getFirstPosition();
 			const context = [
 				...firstPosition.getAncestors(),
-				firstPosition.root.getNodeByPath( firstPosition.path ) || '$text'
+				new Text( '', selection.getAttributes() )
 			];
 
 			// Check whether schema allows for a text with the attribute in the selection.

+ 11 - 1
packages/ckeditor5-engine/tests/model/schema.js

@@ -1083,10 +1083,20 @@ describe( 'Schema', () => {
 				expect( schema.checkAttributeInSelection( doc.selection, attribute ) ).to.be.false;
 			} );
 
-			it( 'should check attributes of text', () => {
+			it( 'should check attributes of text (selection at the beginning of the text)', () => {
+				setData( model, '<p><$text bold="true">[]foo</$text></p>' );
+				expect( schema.checkAttributeInSelection( doc.selection, 'italic' ) ).to.be.false;
+			} );
+
+			it( 'should check attributes of text (selection inside the text)', () => {
 				setData( model, '<p><$text bold="true">f[]oo</$text></p>' );
 				expect( schema.checkAttributeInSelection( doc.selection, 'italic' ) ).to.be.false;
 			} );
+
+			it( 'should check attributes of text (selection at the end of the text)', () => {
+				setData( model, '<p><$text bold="true">foo[]</$text></p>' );
+				expect( schema.checkAttributeInSelection( doc.selection, 'italic' ) ).to.be.false;
+			} );
 		} );
 
 		describe( 'when selection is not collapsed', () => {