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

Commit

Permalink
Code refactoring.
Browse files Browse the repository at this point in the history
  • Loading branch information
oleq committed Apr 4, 2018
1 parent 6a22d47 commit c0122d7
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 11 deletions.
13 changes: 5 additions & 8 deletions src/linkediting.js
Original file line number Diff line number Diff line change
Expand Up @@ -81,15 +81,12 @@ export default class LinkEditing extends Plugin {
*/
_setupLinkHighlight() {
const editor = this.editor;
const model = this.editor.model;
const modelDocument = model.document;
const view = editor.editing.view;
const viewDocument = view.document;
const highlightedLinks = new Set();

// Adding the class.
viewDocument.registerPostFixer( writer => {
const selection = modelDocument.selection;
view.document.registerPostFixer( writer => {
const selection = editor.model.document.selection;

if ( selection.hasAttribute( 'linkHref' ) ) {
const modelRange = findLinkRange( selection.getFirstPosition(), selection.getAttribute( 'linkHref' ) );
Expand All @@ -114,9 +111,9 @@ export default class LinkEditing extends Plugin {
// Removing the class.
function removeHighlight() {
view.change( writer => {
for ( const linkElement of highlightedLinks.values() ) {
writer.removeClass( HIGHLIGHT_CLASSES, linkElement );
highlightedLinks.delete( linkElement );
for ( const item of highlightedLinks.values() ) {
writer.removeClass( HIGHLIGHT_CLASSES, item );
highlightedLinks.delete( item );
}
} );
}
Expand Down
6 changes: 3 additions & 3 deletions tests/linkediting.js
Original file line number Diff line number Diff line change
Expand Up @@ -146,8 +146,8 @@ describe( 'LinkEditing', () => {
} );
} );

describe( 'highlight link boundaries', () => {
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>'
);
Expand Down Expand Up @@ -201,7 +201,7 @@ describe( 'LinkEditing', () => {
expect( model.document.selection.hasAttribute( 'linkHref' ) ).to.be.true;
} );

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>'
);
Expand Down

0 comments on commit c0122d7

Please sign in to comment.