|
|
@@ -8,7 +8,11 @@
|
|
|
*/
|
|
|
|
|
|
import Plugin from '@ckeditor/ckeditor5-core/src/plugin';
|
|
|
-import { downcastAttributeToElement, downcastMarkerToHighlight } from '@ckeditor/ckeditor5-engine/src/conversion/downcast-converters';
|
|
|
+import {
|
|
|
+ downcastAttributeToElement,
|
|
|
+ downcastMarkerToHighlight,
|
|
|
+ createViewElementFromHighlightDescriptor
|
|
|
+} from '@ckeditor/ckeditor5-engine/src/conversion/downcast-converters';
|
|
|
import { upcastElementToAttribute } from '@ckeditor/ckeditor5-engine/src/conversion/upcast-converters';
|
|
|
import LinkCommand from './linkcommand';
|
|
|
import UnlinkCommand from './unlinkcommand';
|
|
|
@@ -18,7 +22,6 @@ import findLinkRange from './findlinkrange';
|
|
|
import '../theme/link.css';
|
|
|
import DocumentSelection from '@ckeditor/ckeditor5-engine/src/model/documentselection';
|
|
|
import ModelSelection from '@ckeditor/ckeditor5-engine/src/model/selection';
|
|
|
-import ViewAttributeElement from '@ckeditor/ckeditor5-engine/src/view/attributeelement';
|
|
|
|
|
|
/**
|
|
|
* The link engine feature.
|
|
|
@@ -89,24 +92,24 @@ export default class LinkEditing extends Plugin {
|
|
|
} ) );
|
|
|
|
|
|
// Create marker over whole link when selection has "linkHref" attribute.
|
|
|
- doc.on( 'change', () => {
|
|
|
+ doc.registerPostFixer( writer => {
|
|
|
const selection = doc.selection;
|
|
|
+ const marker = model.markers.get( 'linkBoundaries' );
|
|
|
|
|
|
// Create marker over link when selection is inside or remove marker otherwise.
|
|
|
if ( selection.hasAttribute( 'linkHref' ) ) {
|
|
|
const modelRange = findLinkRange( selection.getFirstPosition(), selection.getAttribute( 'linkHref' ) );
|
|
|
- const marker = model.markers.get( 'linkBoundaries' );
|
|
|
|
|
|
if ( !marker || !marker.getRange().isEqual( modelRange ) ) {
|
|
|
- model.change( writer => {
|
|
|
- writer.setMarker( 'linkBoundaries', modelRange );
|
|
|
- } );
|
|
|
+ writer.setMarker( 'linkBoundaries', modelRange );
|
|
|
+ return true;
|
|
|
}
|
|
|
- } else if ( model.markers.has( 'linkBoundaries' ) ) {
|
|
|
- model.change( writer => {
|
|
|
- writer.removeMarker( 'linkBoundaries' );
|
|
|
- } );
|
|
|
+ } else if ( marker ) {
|
|
|
+ writer.removeMarker( 'linkBoundaries' );
|
|
|
+ return true;
|
|
|
}
|
|
|
+
|
|
|
+ return false;
|
|
|
} );
|
|
|
|
|
|
// Custom converter for selection's "linkHref" attribute - when collapsed selection has this attribute it is
|
|
|
@@ -128,22 +131,9 @@ export default class LinkEditing extends Plugin {
|
|
|
|
|
|
const writer = conversionApi.writer;
|
|
|
const viewSelection = writer.document.selection;
|
|
|
- const wrapper = new HighlightAttributeElement( 'span', { class: 'ck-link_selected' } );
|
|
|
- wrapper._priority = highlightDescriptor.priority;
|
|
|
- wrapper._setCustomProperty( 'highlightDescriptorId', highlightDescriptor.id );
|
|
|
+ const wrapper = createViewElementFromHighlightDescriptor( highlightDescriptor );
|
|
|
|
|
|
conversionApi.writer.wrap( viewSelection.getFirstRange(), wrapper );
|
|
|
} );
|
|
|
}
|
|
|
}
|
|
|
-
|
|
|
-// Private class used to wrap selection position until https://github.com/ckeditor/ckeditor5-engine/issues/1303 is solved.
|
|
|
-class HighlightAttributeElement extends ViewAttributeElement {
|
|
|
- isSimilar( otherElement ) {
|
|
|
- if ( otherElement.is( 'attributeElement' ) ) {
|
|
|
- return this.getCustomProperty( 'highlightDescriptorId' ) === otherElement.getCustomProperty( 'highlightDescriptorId' );
|
|
|
- }
|
|
|
-
|
|
|
- return false;
|
|
|
- }
|
|
|
-}
|