|
|
@@ -111,7 +111,7 @@ describe( 'Link', () => {
|
|
|
|
|
|
beforeEach( () => {
|
|
|
balloonAddSpy = testUtils.sinon.spy( balloon, 'add' );
|
|
|
- editor.editing.view.isFocused = true;
|
|
|
+ editor.editing.view.document.isFocused = true;
|
|
|
} );
|
|
|
|
|
|
it( 'should not work if the link command is disabled', () => {
|
|
|
@@ -227,27 +227,30 @@ describe( 'Link', () => {
|
|
|
expect( formView.urlInputView.inputView.element.value ).to.equal( '' );
|
|
|
} );
|
|
|
|
|
|
- describe( 'response to view#render', () => {
|
|
|
- it( 'should not duplicate #render listeners', () => {
|
|
|
- const viewDocument = editor.editing.view;
|
|
|
+ describe( 'response to view#change', () => {
|
|
|
+ let view, viewDocument;
|
|
|
|
|
|
+ beforeEach( () => {
|
|
|
+ view = editor.editing.view;
|
|
|
+ viewDocument = view.document;
|
|
|
+ } );
|
|
|
+
|
|
|
+ it( 'should not duplicate #change listeners', () => {
|
|
|
setModelData( editor.model, '<paragraph>f[]oo</paragraph>' );
|
|
|
|
|
|
const spy = testUtils.sinon.stub( balloon, 'updatePosition' ).returns( {} );
|
|
|
|
|
|
linkFeature._showUI();
|
|
|
- viewDocument.render();
|
|
|
+ view.change( () => {} );
|
|
|
linkFeature._hideUI();
|
|
|
|
|
|
linkFeature._showUI();
|
|
|
- viewDocument.render();
|
|
|
+ view.change( () => {} );
|
|
|
sinon.assert.calledTwice( spy );
|
|
|
} );
|
|
|
|
|
|
// https://github.com/ckeditor/ckeditor5-link/issues/113
|
|
|
it( 'updates the position of the panel – editing a link, then the selection remains in the link', () => {
|
|
|
- const viewDocument = editor.editing.view;
|
|
|
-
|
|
|
setModelData( editor.model, '<paragraph><$text linkHref="url">f[]oo</$text></paragraph>' );
|
|
|
|
|
|
linkFeature._showUI();
|
|
|
@@ -257,30 +260,29 @@ describe( 'Link', () => {
|
|
|
const text = root.getChild( 0 ).getChild( 0 ).getChild( 0 );
|
|
|
|
|
|
// Move selection to foo[].
|
|
|
- viewDocument.selection.setTo( Range.createFromParentsAndOffsets( text, 3, text, 3 ), true );
|
|
|
- viewDocument.render();
|
|
|
+ view.change( writer => {
|
|
|
+ writer.setSelection( Range.createFromParentsAndOffsets( text, 3, text, 3 ), true );
|
|
|
+ } );
|
|
|
|
|
|
sinon.assert.calledOnce( spy );
|
|
|
sinon.assert.calledWithExactly( spy, {
|
|
|
- target: viewDocument.domConverter.mapViewToDom( root.getChild( 0 ).getChild( 0 ) )
|
|
|
+ target: view.domConverter.mapViewToDom( root.getChild( 0 ).getChild( 0 ) )
|
|
|
} );
|
|
|
} );
|
|
|
|
|
|
// https://github.com/ckeditor/ckeditor5-link/issues/113
|
|
|
it( 'updates the position of the panel – creating a new link, then the selection moved', () => {
|
|
|
- const viewDocument = editor.editing.view;
|
|
|
-
|
|
|
setModelData( editor.model, '<paragraph>f[]oo</paragraph>' );
|
|
|
|
|
|
linkFeature._showUI();
|
|
|
const spy = testUtils.sinon.stub( balloon, 'updatePosition' ).returns( {} );
|
|
|
|
|
|
- // Fires #render.
|
|
|
const root = viewDocument.getRoot();
|
|
|
const text = root.getChild( 0 ).getChild( 0 );
|
|
|
|
|
|
- viewDocument.selection.setTo( Range.createFromParentsAndOffsets( text, 3, text, 3 ), true );
|
|
|
- viewDocument.render();
|
|
|
+ view.change( writer => {
|
|
|
+ writer.setSelection( Range.createFromParentsAndOffsets( text, 3, text, 3 ), true );
|
|
|
+ } );
|
|
|
|
|
|
sinon.assert.calledOnce( spy );
|
|
|
sinon.assert.calledWithExactly( spy, {
|
|
|
@@ -290,8 +292,6 @@ describe( 'Link', () => {
|
|
|
|
|
|
// https://github.com/ckeditor/ckeditor5-link/issues/113
|
|
|
it( 'hides of the panel – editing a link, then the selection moved out of the link', () => {
|
|
|
- const viewDocument = editor.editing.view;
|
|
|
-
|
|
|
setModelData( editor.model, '<paragraph><$text linkHref="url">f[]oo</$text>bar</paragraph>' );
|
|
|
|
|
|
linkFeature._showUI();
|
|
|
@@ -303,8 +303,9 @@ describe( 'Link', () => {
|
|
|
const text = root.getChild( 0 ).getChild( 1 );
|
|
|
|
|
|
// Move selection to b[]ar.
|
|
|
- viewDocument.selection.setTo( Range.createFromParentsAndOffsets( text, 1, text, 1 ), true );
|
|
|
- viewDocument.render();
|
|
|
+ view.change( writer => {
|
|
|
+ writer.setSelection( Range.createFromParentsAndOffsets( text, 1, text, 1 ), true );
|
|
|
+ } );
|
|
|
|
|
|
sinon.assert.calledOnce( spyHide );
|
|
|
sinon.assert.notCalled( spyUpdate );
|
|
|
@@ -312,8 +313,6 @@ describe( 'Link', () => {
|
|
|
|
|
|
// https://github.com/ckeditor/ckeditor5-link/issues/113
|
|
|
it( 'hides the panel – editing a link, then the selection expands', () => {
|
|
|
- const viewDocument = editor.editing.view;
|
|
|
-
|
|
|
setModelData( editor.model, '<paragraph><$text linkHref="url">f[]oo</$text></paragraph>' );
|
|
|
|
|
|
linkFeature._showUI();
|
|
|
@@ -325,8 +324,9 @@ describe( 'Link', () => {
|
|
|
const text = root.getChild( 0 ).getChild( 0 ).getChild( 0 );
|
|
|
|
|
|
// Move selection to f[o]o.
|
|
|
- viewDocument.selection.setTo( Range.createFromParentsAndOffsets( text, 1, text, 2 ), true );
|
|
|
- viewDocument.render();
|
|
|
+ view.change( writer => {
|
|
|
+ writer.setSelection( Range.createFromParentsAndOffsets( text, 1, text, 2 ), true );
|
|
|
+ } );
|
|
|
|
|
|
sinon.assert.calledOnce( spyHide );
|
|
|
sinon.assert.notCalled( spyUpdate );
|
|
|
@@ -334,8 +334,6 @@ describe( 'Link', () => {
|
|
|
|
|
|
// https://github.com/ckeditor/ckeditor5-link/issues/113
|
|
|
it( 'hides the panel – creating a new link, then the selection moved to another parent', () => {
|
|
|
- const viewDocument = editor.editing.view;
|
|
|
-
|
|
|
setModelData( editor.model, '<paragraph>f[]oo</paragraph><paragraph>bar</paragraph>' );
|
|
|
|
|
|
linkFeature._showUI();
|
|
|
@@ -343,13 +341,13 @@ describe( 'Link', () => {
|
|
|
const spyUpdate = testUtils.sinon.stub( balloon, 'updatePosition' ).returns( {} );
|
|
|
const spyHide = testUtils.sinon.spy( linkFeature, '_hideUI' );
|
|
|
|
|
|
- // Fires #render.
|
|
|
const root = viewDocument.getRoot();
|
|
|
const text = root.getChild( 1 ).getChild( 0 );
|
|
|
|
|
|
// Move selection to f[o]o.
|
|
|
- viewDocument.selection.setTo( Range.createFromParentsAndOffsets( text, 1, text, 2 ), true );
|
|
|
- viewDocument.render();
|
|
|
+ view.change( writer => {
|
|
|
+ writer.setSelection( Range.createFromParentsAndOffsets( text, 1, text, 2 ), true );
|
|
|
+ } );
|
|
|
|
|
|
sinon.assert.calledOnce( spyHide );
|
|
|
sinon.assert.notCalled( spyUpdate );
|
|
|
@@ -394,7 +392,7 @@ describe( 'Link', () => {
|
|
|
|
|
|
linkFeature.listenTo( editor.editing.view, 'render', spy );
|
|
|
linkFeature._hideUI();
|
|
|
- editor.editing.view.render();
|
|
|
+ editor.editing.view.change( () => {} );
|
|
|
|
|
|
sinon.assert.notCalled( spy );
|
|
|
} );
|