|
@@ -10,12 +10,15 @@ import UnlinkCommand from '../src/unlinkcommand';
|
|
|
import VirtualTestEditor from '@ckeditor/ckeditor5-core/tests/_utils/virtualtesteditor';
|
|
import VirtualTestEditor from '@ckeditor/ckeditor5-core/tests/_utils/virtualtesteditor';
|
|
|
import Paragraph from '@ckeditor/ckeditor5-paragraph/src/paragraph';
|
|
import Paragraph from '@ckeditor/ckeditor5-paragraph/src/paragraph';
|
|
|
import Enter from '@ckeditor/ckeditor5-enter/src/enter';
|
|
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 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 { getData as getViewData } from '@ckeditor/ckeditor5-engine/src/dev-utils/view';
|
|
|
import { isLinkElement } from '../src/utils';
|
|
import { isLinkElement } from '../src/utils';
|
|
|
import { keyCodes } from '@ckeditor/ckeditor5-utils/src/keyboard';
|
|
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 */
|
|
/* global document */
|
|
|
|
|
|
|
@@ -232,5 +235,97 @@ describe( 'LinkEditing', () => {
|
|
|
'<p>foo <a class="ck ck-link_selected" href="url">l{}ink</a> 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>'
|
|
|
|
|
+ );
|
|
|
|
|
+ } );
|
|
|
|
|
+ } );
|
|
|
} );
|
|
} );
|
|
|
} );
|
|
} );
|