|
@@ -20,7 +20,6 @@ import { parse, setData as setViewData, getData as getViewData } from '../../src
|
|
|
import { INLINE_FILLER, INLINE_FILLER_LENGTH, isBlockFiller, BR_FILLER } from '../../src/view/filler';
|
|
import { INLINE_FILLER, INLINE_FILLER_LENGTH, isBlockFiller, BR_FILLER } from '../../src/view/filler';
|
|
|
import testUtils from '@ckeditor/ckeditor5-core/tests/_utils/utils';
|
|
import testUtils from '@ckeditor/ckeditor5-core/tests/_utils/utils';
|
|
|
import createElement from '@ckeditor/ckeditor5-utils/src/dom/createelement';
|
|
import createElement from '@ckeditor/ckeditor5-utils/src/dom/createelement';
|
|
|
-import log from '@ckeditor/ckeditor5-utils/src/log';
|
|
|
|
|
import { unwrap, insert, remove } from '../../src/view/writer';
|
|
import { unwrap, insert, remove } from '../../src/view/writer';
|
|
|
import normalizeHtml from '@ckeditor/ckeditor5-utils/tests/_utils/normalizehtml';
|
|
import normalizeHtml from '@ckeditor/ckeditor5-utils/tests/_utils/normalizehtml';
|
|
|
|
|
|
|
@@ -410,6 +409,50 @@ describe( 'Renderer', () => {
|
|
|
expect( viewRoot ).to.be.ok;
|
|
expect( viewRoot ).to.be.ok;
|
|
|
} );
|
|
} );
|
|
|
|
|
|
|
|
|
|
+ it( 'should not add filler when inside contenteditable=false parent', () => {
|
|
|
|
|
+ const { view: viewP, selection: newSelection } = parse(
|
|
|
|
|
+ '<container:p>foo<attribute:b contenteditable="false">[]</attribute:b>bar</container:p>' );
|
|
|
|
|
+
|
|
|
|
|
+ viewRoot.appendChildren( viewP );
|
|
|
|
|
+ selection.setTo( newSelection );
|
|
|
|
|
+
|
|
|
|
|
+ renderer.markToSync( 'children', viewRoot );
|
|
|
|
|
+ renderer.render();
|
|
|
|
|
+
|
|
|
|
|
+ expect( domRoot.childNodes.length ).to.equal( 1 );
|
|
|
|
|
+ expect( domRoot.childNodes[ 0 ].tagName.toLowerCase() ).to.equal( 'p' );
|
|
|
|
|
+
|
|
|
|
|
+ const domP = domRoot.childNodes[ 0 ];
|
|
|
|
|
+
|
|
|
|
|
+ expect( domP.childNodes.length ).to.equal( 3 );
|
|
|
|
|
+ expect( domP.childNodes[ 0 ].data ).to.equal( 'foo' );
|
|
|
|
|
+ expect( domP.childNodes[ 2 ].data ).to.equal( 'bar' );
|
|
|
|
|
+ expect( domP.childNodes[ 1 ].tagName.toLowerCase() ).to.equal( 'b' );
|
|
|
|
|
+ expect( domP.childNodes[ 1 ].childNodes.length ).to.equal( 0 );
|
|
|
|
|
+ } );
|
|
|
|
|
+
|
|
|
|
|
+ it( 'should not add filler when inside contenteditable=false ancestor', () => {
|
|
|
|
|
+ const { view: viewP, selection: newSelection } = parse(
|
|
|
|
|
+ '<container:p contenteditable="false">foo<attribute:b>[]</attribute:b>bar</container:p>' );
|
|
|
|
|
+
|
|
|
|
|
+ viewRoot.appendChildren( viewP );
|
|
|
|
|
+ selection.setTo( newSelection );
|
|
|
|
|
+
|
|
|
|
|
+ renderer.markToSync( 'children', viewRoot );
|
|
|
|
|
+ renderer.render();
|
|
|
|
|
+
|
|
|
|
|
+ expect( domRoot.childNodes.length ).to.equal( 1 );
|
|
|
|
|
+ expect( domRoot.childNodes[ 0 ].tagName.toLowerCase() ).to.equal( 'p' );
|
|
|
|
|
+
|
|
|
|
|
+ const domP = domRoot.childNodes[ 0 ];
|
|
|
|
|
+
|
|
|
|
|
+ expect( domP.childNodes.length ).to.equal( 3 );
|
|
|
|
|
+ expect( domP.childNodes[ 0 ].data ).to.equal( 'foo' );
|
|
|
|
|
+ expect( domP.childNodes[ 2 ].data ).to.equal( 'bar' );
|
|
|
|
|
+ expect( domP.childNodes[ 1 ].tagName.toLowerCase() ).to.equal( 'b' );
|
|
|
|
|
+ expect( domP.childNodes[ 1 ].childNodes.length ).to.equal( 0 );
|
|
|
|
|
+ } );
|
|
|
|
|
+
|
|
|
it( 'should add and remove inline filler in case <p>foo<b>[]</b>bar</p>', () => {
|
|
it( 'should add and remove inline filler in case <p>foo<b>[]</b>bar</p>', () => {
|
|
|
const domSelection = document.getSelection();
|
|
const domSelection = document.getSelection();
|
|
|
|
|
|
|
@@ -1459,11 +1502,7 @@ describe( 'Renderer', () => {
|
|
|
describe( 'similar selection', () => {
|
|
describe( 'similar selection', () => {
|
|
|
// Use spies to check selection updates. Some selection positions are not achievable in some
|
|
// Use spies to check selection updates. Some selection positions are not achievable in some
|
|
|
// browsers (e.g. <p>Foo<b>{}Bar</b></p> in Chrome) so asserting dom selection after rendering would fail.
|
|
// browsers (e.g. <p>Foo<b>{}Bar</b></p> in Chrome) so asserting dom selection after rendering would fail.
|
|
|
- let selectionCollapseSpy, selectionExtendSpy, logWarnStub;
|
|
|
|
|
-
|
|
|
|
|
- before( () => {
|
|
|
|
|
- logWarnStub = sinon.stub( log, 'warn' );
|
|
|
|
|
- } );
|
|
|
|
|
|
|
+ let selectionCollapseSpy, selectionExtendSpy;
|
|
|
|
|
|
|
|
afterEach( () => {
|
|
afterEach( () => {
|
|
|
if ( selectionCollapseSpy ) {
|
|
if ( selectionCollapseSpy ) {
|
|
@@ -1475,11 +1514,6 @@ describe( 'Renderer', () => {
|
|
|
selectionExtendSpy.restore();
|
|
selectionExtendSpy.restore();
|
|
|
selectionExtendSpy = null;
|
|
selectionExtendSpy = null;
|
|
|
}
|
|
}
|
|
|
- logWarnStub.reset();
|
|
|
|
|
- } );
|
|
|
|
|
-
|
|
|
|
|
- after( () => {
|
|
|
|
|
- logWarnStub.restore();
|
|
|
|
|
} );
|
|
} );
|
|
|
|
|
|
|
|
it( 'should always render collapsed selection even if it is similar', () => {
|
|
it( 'should always render collapsed selection even if it is similar', () => {
|
|
@@ -1520,7 +1554,6 @@ describe( 'Renderer', () => {
|
|
|
expect( selectionCollapseSpy.calledWith( domB.childNodes[ 0 ], 0 ) ).to.true;
|
|
expect( selectionCollapseSpy.calledWith( domB.childNodes[ 0 ], 0 ) ).to.true;
|
|
|
expect( selectionExtendSpy.calledOnce ).to.true;
|
|
expect( selectionExtendSpy.calledOnce ).to.true;
|
|
|
expect( selectionExtendSpy.calledWith( domB.childNodes[ 0 ], 0 ) ).to.true;
|
|
expect( selectionExtendSpy.calledWith( domB.childNodes[ 0 ], 0 ) ).to.true;
|
|
|
- expect( logWarnStub.notCalled ).to.true;
|
|
|
|
|
} );
|
|
} );
|
|
|
|
|
|
|
|
it( 'should always render collapsed selection even if it is similar (with empty element)', () => {
|
|
it( 'should always render collapsed selection even if it is similar (with empty element)', () => {
|
|
@@ -1560,7 +1593,6 @@ describe( 'Renderer', () => {
|
|
|
expect( selectionCollapseSpy.calledWith( domP.childNodes[ 0 ], 3 ) ).to.true;
|
|
expect( selectionCollapseSpy.calledWith( domP.childNodes[ 0 ], 3 ) ).to.true;
|
|
|
expect( selectionExtendSpy.calledOnce ).to.true;
|
|
expect( selectionExtendSpy.calledOnce ).to.true;
|
|
|
expect( selectionExtendSpy.calledWith( domP.childNodes[ 0 ], 3 ) ).to.true;
|
|
expect( selectionExtendSpy.calledWith( domP.childNodes[ 0 ], 3 ) ).to.true;
|
|
|
- expect( logWarnStub.notCalled ).to.true;
|
|
|
|
|
} );
|
|
} );
|
|
|
|
|
|
|
|
it( 'should always render non-collapsed selection if it not is similar', () => {
|
|
it( 'should always render non-collapsed selection if it not is similar', () => {
|
|
@@ -1601,7 +1633,6 @@ describe( 'Renderer', () => {
|
|
|
expect( selectionCollapseSpy.calledWith( domP.childNodes[ 0 ], 2 ) ).to.true;
|
|
expect( selectionCollapseSpy.calledWith( domP.childNodes[ 0 ], 2 ) ).to.true;
|
|
|
expect( selectionExtendSpy.calledOnce ).to.true;
|
|
expect( selectionExtendSpy.calledOnce ).to.true;
|
|
|
expect( selectionExtendSpy.calledWith( domB.childNodes[ 0 ], 1 ) ).to.true;
|
|
expect( selectionExtendSpy.calledWith( domB.childNodes[ 0 ], 1 ) ).to.true;
|
|
|
- expect( logWarnStub.notCalled ).to.true;
|
|
|
|
|
} );
|
|
} );
|
|
|
|
|
|
|
|
it( 'should always render selection (even if it is same in view) if current dom selection is in incorrect place', () => {
|
|
it( 'should always render selection (even if it is same in view) if current dom selection is in incorrect place', () => {
|
|
@@ -1669,7 +1700,6 @@ describe( 'Renderer', () => {
|
|
|
|
|
|
|
|
expect( selectionCollapseSpy.notCalled ).to.true;
|
|
expect( selectionCollapseSpy.notCalled ).to.true;
|
|
|
expect( selectionExtendSpy.notCalled ).to.true;
|
|
expect( selectionExtendSpy.notCalled ).to.true;
|
|
|
- expect( logWarnStub.called ).to.true;
|
|
|
|
|
} );
|
|
} );
|
|
|
|
|
|
|
|
it( 'should not render non-collapsed selection it is similar (element end)', () => {
|
|
it( 'should not render non-collapsed selection it is similar (element end)', () => {
|
|
@@ -1708,7 +1738,6 @@ describe( 'Renderer', () => {
|
|
|
|
|
|
|
|
expect( selectionCollapseSpy.notCalled ).to.true;
|
|
expect( selectionCollapseSpy.notCalled ).to.true;
|
|
|
expect( selectionExtendSpy.notCalled ).to.true;
|
|
expect( selectionExtendSpy.notCalled ).to.true;
|
|
|
- expect( logWarnStub.called ).to.true;
|
|
|
|
|
} );
|
|
} );
|
|
|
|
|
|
|
|
it( 'should not render non-collapsed selection it is similar (element start - nested)', () => {
|
|
it( 'should not render non-collapsed selection it is similar (element start - nested)', () => {
|
|
@@ -1747,7 +1776,6 @@ describe( 'Renderer', () => {
|
|
|
|
|
|
|
|
expect( selectionCollapseSpy.notCalled ).to.true;
|
|
expect( selectionCollapseSpy.notCalled ).to.true;
|
|
|
expect( selectionExtendSpy.notCalled ).to.true;
|
|
expect( selectionExtendSpy.notCalled ).to.true;
|
|
|
- expect( logWarnStub.called ).to.true;
|
|
|
|
|
} );
|
|
} );
|
|
|
|
|
|
|
|
it( 'should not render non-collapsed selection it is similar (element end - nested)', () => {
|
|
it( 'should not render non-collapsed selection it is similar (element end - nested)', () => {
|
|
@@ -1785,7 +1813,6 @@ describe( 'Renderer', () => {
|
|
|
|
|
|
|
|
expect( selectionCollapseSpy.notCalled ).to.true;
|
|
expect( selectionCollapseSpy.notCalled ).to.true;
|
|
|
expect( selectionExtendSpy.notCalled ).to.true;
|
|
expect( selectionExtendSpy.notCalled ).to.true;
|
|
|
- expect( logWarnStub.called ).to.true;
|
|
|
|
|
} );
|
|
} );
|
|
|
} );
|
|
} );
|
|
|
} );
|
|
} );
|