|
@@ -495,6 +495,82 @@ describe( 'Renderer', () => {
|
|
|
expect( domSelection.getRangeAt( 0 ).collapsed ).to.be.true;
|
|
expect( domSelection.getRangeAt( 0 ).collapsed ).to.be.true;
|
|
|
} );
|
|
} );
|
|
|
|
|
|
|
|
|
|
+ it( 'should move filler when selection is moved', () => {
|
|
|
|
|
+ // Step 1: <p>foo<b>"FILLER{}"</b></p>
|
|
|
|
|
+ const { view: viewP, selection: newSelection } = parse(
|
|
|
|
|
+ '<container:p>foo<attribute:b>[]</attribute:b><attribute:i></attribute:i></container:p>' );
|
|
|
|
|
+
|
|
|
|
|
+ viewRoot.appendChildren( viewP );
|
|
|
|
|
+ selection.setTo( newSelection );
|
|
|
|
|
+
|
|
|
|
|
+ renderer.markToSync( 'children', viewRoot );
|
|
|
|
|
+
|
|
|
|
|
+ renderer.render();
|
|
|
|
|
+
|
|
|
|
|
+ const domP = domRoot.childNodes[ 0 ];
|
|
|
|
|
+
|
|
|
|
|
+ expect( domP.childNodes.length ).to.equal( 3 );
|
|
|
|
|
+ expect( domP.childNodes[ 0 ].data ).to.equal( 'foo' );
|
|
|
|
|
+ expect( domP.childNodes[ 1 ].tagName.toLowerCase() ).to.equal( 'b' );
|
|
|
|
|
+ expect( domP.childNodes[ 1 ].childNodes.length ).to.equal( 1 );
|
|
|
|
|
+ expect( domP.childNodes[ 1 ].childNodes[ 0 ].data ).to.equal( INLINE_FILLER );
|
|
|
|
|
+ expect( domP.childNodes[ 2 ].tagName.toLowerCase() ).to.equal( 'i' );
|
|
|
|
|
+ expect( domP.childNodes[ 2 ].childNodes.length ).to.equal( 0 );
|
|
|
|
|
+
|
|
|
|
|
+ // Step 2: <p>foo<b></b><i>"FILLER{}"</i></p>
|
|
|
|
|
+ selection.removeAllRanges();
|
|
|
|
|
+ const viewI = viewP.getChild( 2 );
|
|
|
|
|
+ selection.addRange( ViewRange.createFromParentsAndOffsets( viewI, 0, viewI, 0 ) );
|
|
|
|
|
+
|
|
|
|
|
+ renderer.render();
|
|
|
|
|
+
|
|
|
|
|
+ expect( domP.childNodes.length ).to.equal( 3 );
|
|
|
|
|
+ expect( domP.childNodes[ 0 ].data ).to.equal( 'foo' );
|
|
|
|
|
+ expect( domP.childNodes[ 1 ].tagName.toLowerCase() ).to.equal( 'b' );
|
|
|
|
|
+ expect( domP.childNodes[ 1 ].childNodes.length ).to.equal( 0 );
|
|
|
|
|
+ expect( domP.childNodes[ 2 ].tagName.toLowerCase() ).to.equal( 'i' );
|
|
|
|
|
+ expect( domP.childNodes[ 2 ].childNodes.length ).to.equal( 1 );
|
|
|
|
|
+ expect( domP.childNodes[ 2 ].childNodes[ 0 ].data ).to.equal( INLINE_FILLER );
|
|
|
|
|
+ } );
|
|
|
|
|
+
|
|
|
|
|
+ it( 'should remove filler when text is added and selection removed', () => {
|
|
|
|
|
+ // Step 1: <p>foo<b>"FILLER{}"</b></p>
|
|
|
|
|
+ const { view: viewP, selection: newSelection } = parse( '<container:p>foo<attribute:b>[]</attribute:b></container:p>' );
|
|
|
|
|
+ const viewB = viewP.getChild( 1 );
|
|
|
|
|
+ viewRoot.appendChildren( viewP );
|
|
|
|
|
+ selection.setTo( newSelection );
|
|
|
|
|
+
|
|
|
|
|
+ renderer.markToSync( 'children', viewRoot );
|
|
|
|
|
+ renderer.render();
|
|
|
|
|
+
|
|
|
|
|
+ const domP = domRoot.childNodes[ 0 ];
|
|
|
|
|
+ expect( domP.childNodes.length ).to.equal( 2 );
|
|
|
|
|
+ expect( domP.childNodes[ 0 ].data ).to.equal( 'foo' );
|
|
|
|
|
+ expect( domP.childNodes[ 1 ].tagName.toLowerCase() ).to.equal( 'b' );
|
|
|
|
|
+ expect( domP.childNodes[ 1 ].childNodes.length ).to.equal( 1 );
|
|
|
|
|
+ expect( domP.childNodes[ 1 ].childNodes[ 0 ].data ).to.equal( INLINE_FILLER );
|
|
|
|
|
+
|
|
|
|
|
+ // Step 2: Add text node.
|
|
|
|
|
+ const viewText = new ViewText( 'x' );
|
|
|
|
|
+ viewB.appendChildren( viewText );
|
|
|
|
|
+ selection.removeAllRanges();
|
|
|
|
|
+ selection.addRange( ViewRange.createFromParentsAndOffsets( viewText, 1, viewText, 1 ) );
|
|
|
|
|
+
|
|
|
|
|
+ renderer.markToSync( 'children', viewB );
|
|
|
|
|
+ renderer.render();
|
|
|
|
|
+
|
|
|
|
|
+ // Step 3: Remove selection from the view.
|
|
|
|
|
+ selection.removeAllRanges();
|
|
|
|
|
+
|
|
|
|
|
+ renderer.render();
|
|
|
|
|
+
|
|
|
|
|
+ expect( domP.childNodes.length ).to.equal( 2 );
|
|
|
|
|
+ expect( domP.childNodes[ 0 ].data ).to.equal( 'foo' );
|
|
|
|
|
+ expect( domP.childNodes[ 1 ].tagName.toLowerCase() ).to.equal( 'b' );
|
|
|
|
|
+ expect( domP.childNodes[ 1 ].childNodes.length ).to.equal( 1 );
|
|
|
|
|
+ expect( domP.childNodes[ 1 ].childNodes[ 0 ].data ).to.equal( 'x' );
|
|
|
|
|
+ } );
|
|
|
|
|
+
|
|
|
it( 'should handle typing in empty block, do nothing if changes are already applied', () => {
|
|
it( 'should handle typing in empty block, do nothing if changes are already applied', () => {
|
|
|
const domSelection = document.getSelection();
|
|
const domSelection = document.getSelection();
|
|
|
|
|
|