8
0
Просмотр исходного кода

Added additional tests which check whether the `LiveSelection` mechanism works properly.

Kamil Piechaczek 8 лет назад
Родитель
Сommit
c3dc273f33

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

@@ -7,7 +7,6 @@
  * @module engine/model/liveselection
  */
 
-import Element from './element';
 import Position from './position';
 import Range from './range';
 import LiveRange from './liverange';
@@ -568,7 +567,7 @@ export default class LiveSelection extends Selection {
 			// ...look for a first character node in that range and take attributes from it.
 			for ( const item of range ) {
 				// If the item is an object, we don't want to get attributes from its children.
-				if ( item.item instanceof Element && schema.objects.has( item.item.name ) ) {
+				if ( item.item.is( 'element' ) && schema.objects.has( item.item.name ) ) {
 					break;
 				}
 

+ 18 - 12
packages/ckeditor5-engine/tests/model/liveselection.js

@@ -885,24 +885,30 @@ describe( 'LiveSelection', () => {
 			doc.schema.allow( { name: '$text', attributes: 'bold', inside: 'caption' } );
 
 			root.removeChildren( 0, root.childCount );
-
-			root.insertChildren( 0, [
-				new Element( 'p', null, [
-					new Element( 'image', [], [
-						new Element( 'caption', [], [
-							new Text( 'Caption for the image.', { bold: true } )
-						] )
-					] )
-				] )
-			] );
-
-			selection.addRange( new Range( new Position( root, [ 0 ] ), new Position( root, [ 1 ] ) ) );
 		} );
 
 		it( 'ignores attributes from nested editable if selection contains an object', () => {
+			setData( doc, '<p>[<image><caption>Caption for the image.</caption></image>]</p>' );
+
 			const liveSelection = LiveSelection.createFromSelection( selection );
 
 			expect( liveSelection.hasAttribute( 'bold' ) ).to.equal( false );
 		} );
+
+		it( 'read attributes from text even if the selection contains an object', () => {
+			setData( doc, '<p>x[<$text bold="true">bar</$text><image></image>foo]</p>' );
+
+			const liveSelection = LiveSelection.createFromSelection( selection );
+
+			expect( liveSelection.hasAttribute( 'bold' ) ).to.equal( true );
+		} );
+
+		it( 'read attributes from editable if selection contains elements inside the object', () => {
+			setData( doc, '<p><image>[<caption><$text bold="true">bar</$text></caption>]</image></p>' );
+
+			const liveSelection = LiveSelection.createFromSelection( selection );
+
+			expect( liveSelection.hasAttribute( 'bold' ) ).to.equal( true );
+		} );
 	} );
 } );