|
|
@@ -1047,6 +1047,26 @@ describe( 'Schema', () => {
|
|
|
return true;
|
|
|
}
|
|
|
} );
|
|
|
+
|
|
|
+ schema.addAttributeCheck( ( ctx, attributeName ) => {
|
|
|
+ // Disallow 'italic' on $text that has attribute 'bold'.
|
|
|
+ if ( inTextWithBold( ctx ) && attributeName == 'italic' ) {
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+ // Allow 'italic' on p>$text.
|
|
|
+ if ( ctx.endsWith( 'p $text' ) && attributeName == 'italic' ) {
|
|
|
+ return true;
|
|
|
+ }
|
|
|
+
|
|
|
+ // Allow 'italic' on $root>p.
|
|
|
+ if ( ctx.endsWith( '$root p' ) && attributeName == 'italic' ) {
|
|
|
+ return true;
|
|
|
+ }
|
|
|
+
|
|
|
+ function inTextWithBold( context ) {
|
|
|
+ return context.endsWith( '$text' ) && context.last.getAttribute( 'bold' );
|
|
|
+ }
|
|
|
+ } );
|
|
|
} );
|
|
|
|
|
|
describe( 'when selection is collapsed', () => {
|
|
|
@@ -1062,6 +1082,11 @@ describe( 'Schema', () => {
|
|
|
setData( model, '[]' );
|
|
|
expect( schema.checkAttributeInSelection( doc.selection, attribute ) ).to.be.false;
|
|
|
} );
|
|
|
+
|
|
|
+ it( 'should check attributes of text', () => {
|
|
|
+ setData( model, '<p><$text bold="true">f[]oo</$text></p>' );
|
|
|
+ expect( schema.checkAttributeInSelection( doc.selection, 'italic' ) ).to.be.false;
|
|
|
+ } );
|
|
|
} );
|
|
|
|
|
|
describe( 'when selection is not collapsed', () => {
|
|
|
@@ -1102,6 +1127,11 @@ describe( 'Schema', () => {
|
|
|
setData( model, '[<figure name="figure" title="title"></figure>]' );
|
|
|
expect( schema.checkAttributeInSelection( doc.selection, 'title' ) ).to.be.true;
|
|
|
} );
|
|
|
+
|
|
|
+ it( 'should check attributes of text', () => {
|
|
|
+ setData( model, '<p><$text bold="true">f[o]o</$text></p>' );
|
|
|
+ expect( schema.checkAttributeInSelection( doc.selection, 'italic' ) ).to.be.false;
|
|
|
+ } );
|
|
|
} );
|
|
|
} );
|
|
|
|