|
|
@@ -10,12 +10,15 @@ import UnlinkCommand from '../src/unlinkcommand';
|
|
|
import VirtualTestEditor from '@ckeditor/ckeditor5-core/tests/_utils/virtualtesteditor';
|
|
|
import Paragraph from '@ckeditor/ckeditor5-paragraph/src/paragraph';
|
|
|
import Enter from '@ckeditor/ckeditor5-enter/src/enter';
|
|
|
+import ModelRange from '@ckeditor/ckeditor5-engine/src/model/range';
|
|
|
import { getData as getModelData, setData as setModelData } from '@ckeditor/ckeditor5-engine/src/dev-utils/model';
|
|
|
import { getData as getViewData } from '@ckeditor/ckeditor5-engine/src/dev-utils/view';
|
|
|
import { isLinkElement } from '../src/utils';
|
|
|
import { keyCodes } from '@ckeditor/ckeditor5-utils/src/keyboard';
|
|
|
-
|
|
|
-import { downcastAttributeToElement } from '@ckeditor/ckeditor5-engine/src/conversion/downcast-converters';
|
|
|
+import {
|
|
|
+ downcastMarkerToHighlight,
|
|
|
+ downcastAttributeToElement
|
|
|
+} from '@ckeditor/ckeditor5-engine/src/conversion/downcast-converters';
|
|
|
|
|
|
/* global document */
|
|
|
|
|
|
@@ -146,27 +149,15 @@ describe( 'LinkEditing', () => {
|
|
|
} );
|
|
|
} );
|
|
|
|
|
|
- describe( 'highlight link boundaries', () => {
|
|
|
- it( 'should create marker in model when selection is inside a link', () => {
|
|
|
- expect( model.markers.has( 'linkBoundaries' ) ).to.be.false;
|
|
|
-
|
|
|
- setModelData( model,
|
|
|
- '<paragraph>foo <$text linkHref="url">b{}ar</$text> baz</paragraph>'
|
|
|
- );
|
|
|
-
|
|
|
- expect( model.markers.has( 'linkBoundaries' ) ).to.be.true;
|
|
|
- const marker = model.markers.get( 'linkBoundaries' );
|
|
|
- expect( marker.getStart().path ).to.deep.equal( [ 0, 4 ] );
|
|
|
- expect( marker.getEnd().path ).to.deep.equal( [ 0, 7 ] );
|
|
|
- } );
|
|
|
-
|
|
|
- it( 'should convert link boundaries marker to proper view', () => {
|
|
|
+ describe( 'link highlighting', () => {
|
|
|
+ it( 'should convert the highlight to a proper view classes', () => {
|
|
|
setModelData( model,
|
|
|
'<paragraph>foo <$text linkHref="url">b{}ar</$text> baz</paragraph>'
|
|
|
);
|
|
|
|
|
|
+ expect( model.document.selection.hasAttribute( 'linkHref' ) ).to.be.true;
|
|
|
expect( getViewData( view ) ).to.equal(
|
|
|
- '<p>foo <span class="ck ck-link_selected"><a href="url">b{}ar</a></span> baz</p>'
|
|
|
+ '<p>foo <a class="ck ck-link_selected" href="url">b{}ar</a> baz</p>'
|
|
|
);
|
|
|
} );
|
|
|
|
|
|
@@ -182,13 +173,8 @@ describe( 'LinkEditing', () => {
|
|
|
} );
|
|
|
|
|
|
expect( model.document.selection.hasAttribute( 'linkHref' ) ).to.be.true;
|
|
|
- expect( model.markers.has( 'linkBoundaries' ) ).to.be.true;
|
|
|
- const marker = model.markers.get( 'linkBoundaries' );
|
|
|
- expect( marker.getStart().path ).to.deep.equal( [ 0, 4 ] );
|
|
|
- expect( marker.getEnd().path ).to.deep.equal( [ 0, 7 ] );
|
|
|
-
|
|
|
expect( getViewData( view ) ).to.equal(
|
|
|
- '<p>foo <span class="ck ck-link_selected"><a href="url">{}bar</a></span> baz</p>'
|
|
|
+ '<p>foo <a class="ck ck-link_selected" href="url">{}bar</a> baz</p>'
|
|
|
);
|
|
|
} );
|
|
|
|
|
|
@@ -198,13 +184,8 @@ describe( 'LinkEditing', () => {
|
|
|
);
|
|
|
|
|
|
expect( model.document.selection.hasAttribute( 'linkHref' ) ).to.be.true;
|
|
|
- expect( model.markers.has( 'linkBoundaries' ) ).to.be.true;
|
|
|
- const marker = model.markers.get( 'linkBoundaries' );
|
|
|
- expect( marker.getStart().path ).to.deep.equal( [ 0, 4 ] );
|
|
|
- expect( marker.getEnd().path ).to.deep.equal( [ 0, 7 ] );
|
|
|
-
|
|
|
expect( getViewData( view ) ).to.equal(
|
|
|
- '<p>foo <span class="ck ck-link_selected"><a href="url">bar{}</a></span> baz</p>'
|
|
|
+ '<p>foo <a class="ck ck-link_selected" href="url">bar{}</a> baz</p>'
|
|
|
);
|
|
|
} );
|
|
|
|
|
|
@@ -221,25 +202,19 @@ describe( 'LinkEditing', () => {
|
|
|
);
|
|
|
|
|
|
expect( model.document.selection.hasAttribute( 'linkHref' ) ).to.be.true;
|
|
|
- expect( model.markers.has( 'linkBoundaries' ) ).to.be.true;
|
|
|
- const marker = model.markers.get( 'linkBoundaries' );
|
|
|
- expect( marker.getStart().path ).to.deep.equal( [ 1, 0 ] );
|
|
|
- expect( marker.getEnd().path ).to.deep.equal( [ 1, 2 ] );
|
|
|
} );
|
|
|
|
|
|
- it( 'should remove marker when selection is moved out from the link', () => {
|
|
|
+ it( 'should remove classes when selection is moved out from the link', () => {
|
|
|
setModelData( model,
|
|
|
'<paragraph>foo <$text linkHref="url">li{}nk</$text> baz</paragraph>'
|
|
|
);
|
|
|
|
|
|
expect( getViewData( view ) ).to.equal(
|
|
|
- '<p>foo <span class="ck ck-link_selected"><a href="url">li{}nk</a></span> baz</p>'
|
|
|
+ '<p>foo <a class="ck ck-link_selected" href="url">li{}nk</a> baz</p>'
|
|
|
);
|
|
|
|
|
|
- expect( model.markers.has( 'linkBoundaries' ) ).to.be.true;
|
|
|
model.change( writer => writer.setSelection( model.document.getRoot().getChild( 0 ), 0 ) );
|
|
|
|
|
|
- expect( model.markers.has( 'linkBoundaries' ) ).to.be.false;
|
|
|
expect( getViewData( view ) ).to.equal(
|
|
|
'<p>{}foo <a href="url">link</a> baz</p>'
|
|
|
);
|
|
|
@@ -251,16 +226,106 @@ describe( 'LinkEditing', () => {
|
|
|
);
|
|
|
|
|
|
expect( getViewData( view ) ).to.equal(
|
|
|
- '<p>foo <span class="ck ck-link_selected"><a href="url">li{}nk</a></span> baz</p>'
|
|
|
+ '<p>foo <a class="ck ck-link_selected" href="url">li{}nk</a> baz</p>'
|
|
|
);
|
|
|
|
|
|
- expect( model.markers.has( 'linkBoundaries' ) ).to.be.true;
|
|
|
model.change( writer => writer.setSelection( model.document.getRoot().getChild( 0 ), 5 ) );
|
|
|
|
|
|
- expect( model.markers.has( 'linkBoundaries' ) ).to.be.true;
|
|
|
expect( getViewData( view ) ).to.equal(
|
|
|
- '<p>foo <span class="ck ck-link_selected"><a href="url">l{}ink</a></span> baz</p>'
|
|
|
+ '<p>foo <a class="ck ck-link_selected" href="url">l{}ink</a> baz</p>'
|
|
|
);
|
|
|
} );
|
|
|
+
|
|
|
+ describe( 'downcast conversion integration', () => {
|
|
|
+ it( 'works for the #insert event', () => {
|
|
|
+ setModelData( model,
|
|
|
+ '<paragraph>foo <$text linkHref="url">li{}nk</$text> baz</paragraph>'
|
|
|
+ );
|
|
|
+
|
|
|
+ model.change( writer => {
|
|
|
+ writer.insertText( 'FOO', { linkHref: 'url' }, model.document.selection.getFirstPosition() );
|
|
|
+ } );
|
|
|
+
|
|
|
+ expect( getViewData( view ) ).to.equal(
|
|
|
+ '<p>foo <a class="ck ck-link_selected" href="url">liFOO{}nk</a> baz</p>'
|
|
|
+ );
|
|
|
+ } );
|
|
|
+
|
|
|
+ it( 'works for the #remove event', () => {
|
|
|
+ setModelData( model,
|
|
|
+ '<paragraph>foo <$text linkHref="url">li{}nk</$text> baz</paragraph>'
|
|
|
+ );
|
|
|
+
|
|
|
+ model.change( writer => {
|
|
|
+ writer.remove( ModelRange.createFromParentsAndOffsets(
|
|
|
+ model.document.getRoot().getChild( 0 ), 0,
|
|
|
+ model.document.getRoot().getChild( 0 ), 5 )
|
|
|
+ );
|
|
|
+ } );
|
|
|
+
|
|
|
+ expect( getViewData( view ) ).to.equal(
|
|
|
+ '<p><a class="ck ck-link_selected" href="url">i{}nk</a> baz</p>'
|
|
|
+ );
|
|
|
+ } );
|
|
|
+
|
|
|
+ it( 'works for the #attribute event', () => {
|
|
|
+ setModelData( model,
|
|
|
+ '<paragraph>foo <$text linkHref="url">li{}nk</$text> baz</paragraph>'
|
|
|
+ );
|
|
|
+
|
|
|
+ model.change( writer => {
|
|
|
+ writer.setAttribute( 'linkHref', 'new-url', new ModelRange(
|
|
|
+ model.document.selection.getFirstPosition().getShiftedBy( -1 ),
|
|
|
+ model.document.selection.getFirstPosition().getShiftedBy( 1 ) )
|
|
|
+ );
|
|
|
+ } );
|
|
|
+
|
|
|
+ expect( getViewData( view ) ).to.equal(
|
|
|
+ '<p>foo <a href="url">l</a><a class="ck ck-link_selected" href="new-url">i{}n</a><a href="url">k</a> baz</p>'
|
|
|
+ );
|
|
|
+ } );
|
|
|
+
|
|
|
+ it( 'works for the #selection event', () => {
|
|
|
+ setModelData( model,
|
|
|
+ '<paragraph>foo <$text linkHref="url">li{}nk</$text> baz</paragraph>'
|
|
|
+ );
|
|
|
+
|
|
|
+ model.change( writer => {
|
|
|
+ writer.setSelection( new ModelRange(
|
|
|
+ model.document.selection.getFirstPosition().getShiftedBy( -1 ),
|
|
|
+ model.document.selection.getFirstPosition().getShiftedBy( 1 ) )
|
|
|
+ );
|
|
|
+ } );
|
|
|
+
|
|
|
+ expect( getViewData( view ) ).to.equal(
|
|
|
+ '<p>foo <a class="ck ck-link_selected" href="url">l{in}k</a> baz</p>'
|
|
|
+ );
|
|
|
+ } );
|
|
|
+
|
|
|
+ it( 'works for the #addMarker and #removeMarker events', () => {
|
|
|
+ downcastMarkerToHighlight( { model: 'fooMarker', view: {} } )( editor.editing.downcastDispatcher );
|
|
|
+
|
|
|
+ setModelData( model,
|
|
|
+ '<paragraph>foo <$text linkHref="url">li{}nk</$text> baz</paragraph>'
|
|
|
+ );
|
|
|
+
|
|
|
+ model.change( writer => {
|
|
|
+ writer.setMarker( 'fooMarker', ModelRange.createFromParentsAndOffsets(
|
|
|
+ model.document.getRoot().getChild( 0 ), 0,
|
|
|
+ model.document.getRoot().getChild( 0 ), 5 )
|
|
|
+ );
|
|
|
+ } );
|
|
|
+
|
|
|
+ expect( getViewData( view ) ).to.equal(
|
|
|
+ '<p><span>foo </span><a class="ck ck-link_selected" href="url"><span>l</span>i{}nk</a> baz</p>'
|
|
|
+ );
|
|
|
+
|
|
|
+ model.change( writer => writer.removeMarker( 'fooMarker' ) );
|
|
|
+
|
|
|
+ expect( getViewData( view ) ).to.equal(
|
|
|
+ '<p>foo <a class="ck ck-link_selected" href="url">li{}nk</a> baz</p>'
|
|
|
+ );
|
|
|
+ } );
|
|
|
+ } );
|
|
|
} );
|
|
|
} );
|