Skip to content
This repository has been archived by the owner on Jun 26, 2020. It is now read-only.

Commit

Permalink
Used writer instead of protected methods to add and remove the link h…
Browse files Browse the repository at this point in the history
…ighlight.
  • Loading branch information
oleq committed Apr 4, 2018
1 parent 629e017 commit 466db91
Showing 1 changed file with 6 additions and 6 deletions.
12 changes: 6 additions & 6 deletions src/linkediting.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ import bindTwoStepCaretToAttribute from '@ckeditor/ckeditor5-engine/src/utils/bi
import findLinkRange from './findlinkrange';
import '../theme/link.css';

const HIGHLIGHT_CLASSES = 'ck ck-link_selected';
const HIGHLIGHT_CLASSES = [ 'ck', 'ck-link_selected' ];

/**
* The link engine feature.
Expand Down Expand Up @@ -88,16 +88,16 @@ export default class LinkEditing extends Plugin {
const highlightedLinks = new Set();

// Adding the class.
viewDocument.registerPostFixer( () => {
viewDocument.registerPostFixer( writer => {
const selection = modelDocument.selection;

if ( selection.hasAttribute( 'linkHref' ) ) {
const modelRange = findLinkRange( selection.getFirstPosition(), selection.getAttribute( 'linkHref' ) );
const viewRange = editor.editing.mapper.toViewRange( modelRange );

for ( const item of viewRange.getItems() ) {
if ( item.is( 'attributeElement' ) && item.name == 'a' ) {
item._addClass( HIGHLIGHT_CLASSES );
if ( item.is( 'a' ) ) {
writer.addClass( HIGHLIGHT_CLASSES, item );
highlightedLinks.add( item );
}
}
Expand All @@ -113,9 +113,9 @@ export default class LinkEditing extends Plugin {

// Removing the class.
function removeHighlight() {
view.change( () => {
view.change( writer => {
for ( const linkElement of highlightedLinks.values() ) {
linkElement._removeClass( HIGHLIGHT_CLASSES );
writer.removeClass( HIGHLIGHT_CLASSES, linkElement );
highlightedLinks.delete( linkElement );
}
} );
Expand Down

0 comments on commit 466db91

Please sign in to comment.