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

Commit

Permalink
Internal: Use schema helpers instead of deprecated core command helpe…
Browse files Browse the repository at this point in the history
…rs. Closes #131.
  • Loading branch information
Reinmar committed Jun 19, 2017
1 parent 41da2e4 commit 4ecb8bf
Showing 1 changed file with 6 additions and 8 deletions.
14 changes: 6 additions & 8 deletions src/linkcommand.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,6 @@
import Command from '@ckeditor/ckeditor5-core/src/command';
import Text from '@ckeditor/ckeditor5-engine/src/model/text';
import Range from '@ckeditor/ckeditor5-engine/src/model/range';
import getSchemaValidRanges from '@ckeditor/ckeditor5-core/src/command/helpers/getschemavalidranges';
import isAttributeAllowedInSelection from '@ckeditor/ckeditor5-core/src/command/helpers/isattributeallowedinselection';
import findLinkRange from './findlinkrange';

/**
Expand All @@ -35,7 +33,7 @@ export default class LinkCommand extends Command {
const doc = this.editor.document;

this.value = doc.selection.getAttribute( 'linkHref' );
this.isEnabled = isAttributeAllowedInSelection( 'linkHref', doc.selection, doc.schema );
this.isEnabled = doc.schema.checkAttributeInSelection( doc.selection, 'linkHref' );
}

/**
Expand All @@ -55,12 +53,12 @@ export default class LinkCommand extends Command {
* @param {String} href Link destination.
*/
execute( href ) {
const document = this.editor.document;
const selection = document.selection;
const doc = this.editor.document;
const selection = doc.selection;

document.enqueueChanges( () => {
doc.enqueueChanges( () => {
// Keep it as one undo step.
const batch = document.batch();
const batch = doc.batch();

// If selection is collapsed then update selected link or insert new one at the place of caret.
if ( selection.isCollapsed ) {
Expand Down Expand Up @@ -88,7 +86,7 @@ export default class LinkCommand extends Command {
} else {
// If selection has non-collapsed ranges, we change attribute on nodes inside those ranges
// omitting nodes where `linkHref` attribute is disallowed.
const ranges = getSchemaValidRanges( 'linkHref', selection.getRanges(), document.schema );
const ranges = doc.schema.getValidRanges( selection.getRanges(), 'linkHref' );

for ( const range of ranges ) {
batch.setAttribute( range, 'linkHref', href );
Expand Down

0 comments on commit 4ecb8bf

Please sign in to comment.