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

Commit

Permalink
Other: Aligned the implementation to the new Command API (see https:/…
Browse files Browse the repository at this point in the history
…/github.com/ckeditor/ckeditor5-core/issues/88).

BREAKING CHANGES: The command API has been changed.
  • Loading branch information
szymonkups committed Jun 13, 2017
2 parents d0cee1f + 53e5a5f commit f20ef7d
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 18 deletions.
14 changes: 6 additions & 8 deletions src/autoformat.js
Original file line number Diff line number Diff line change
Expand Up @@ -79,12 +79,12 @@ export default class Autoformat extends Plugin {
_addListAutoformats() {
const commands = this.editor.commands;

if ( commands.has( 'bulletedList' ) ) {
if ( commands.get( 'bulletedList' ) ) {
// eslint-disable-next-line no-new
new BlockAutoformatEngine( this.editor, /^[*-]\s$/, 'bulletedList' );
}

if ( commands.has( 'numberedList' ) ) {
if ( commands.get( 'numberedList' ) ) {
// eslint-disable-next-line no-new
new BlockAutoformatEngine( this.editor, /^\d+[.|)]?\s$/, 'numberedList' );
}
Expand All @@ -105,14 +105,14 @@ export default class Autoformat extends Plugin {
_addBasicStylesAutoformats() {
const commands = this.editor.commands;

if ( commands.has( 'bold' ) ) {
if ( commands.get( 'bold' ) ) {
/* eslint-disable no-new */
new InlineAutoformatEngine( this.editor, /(\*\*)([^*]+)(\*\*)$/g, 'bold' );
new InlineAutoformatEngine( this.editor, /(__)([^_]+)(__)$/g, 'bold' );
/* eslint-enable no-new */
}

if ( commands.has( 'italic' ) ) {
if ( commands.get( 'italic' ) ) {
// The italic autoformatter cannot be triggered by the bold markers, so we need to check the
// text before the pattern (e.g. `(?:^|[^\*])`).

Expand All @@ -135,9 +135,7 @@ export default class Autoformat extends Plugin {
* @private
*/
_addHeadingAutoformats() {
const commands = this.editor.commands;

Array.from( commands.keys() )
Array.from( this.editor.commands.names() )
.filter( name => name.match( /^heading[1-6]$/ ) )
.forEach( commandName => {
const level = commandName[ 7 ];
Expand All @@ -160,7 +158,7 @@ export default class Autoformat extends Plugin {
* @private
*/
_addBlockQuoteAutoformats() {
if ( this.editor.commands.has( 'blockQuote' ) ) {
if ( this.editor.commands.get( 'blockQuote' ) ) {
// eslint-disable-next-line no-new
new BlockAutoformatEngine( this.editor, /^>\s$/, 'blockQuote' );
}
Expand Down
10 changes: 5 additions & 5 deletions tests/autoformat.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ import VirtualTestEditor from '@ckeditor/ckeditor5-core/tests/_utils/virtualtest
import { setData, getData } from '@ckeditor/ckeditor5-engine/src/dev-utils/model';
import testUtils from '@ckeditor/ckeditor5-core/tests/_utils/utils';

import Command from '@ckeditor/ckeditor5-core/src/command/command';
import Command from '@ckeditor/ckeditor5-core/src/command';

testUtils.createSinonSandbox();

Expand Down Expand Up @@ -122,19 +122,19 @@ describe( 'Autoformat', () => {
const spy6 = sinon.spy();

class Heading6 extends Command {
_doExecute() {
execute() {
spy6();
}
}
class Heading1 extends Command {
_doExecute() {
execute() {
spy1();
}
}

function HeadingPlugin( editor ) {
editor.commands.set( 'heading1', new Heading1() );
editor.commands.set( 'heading6', new Heading6() );
editor.commands.add( 'heading1', new Heading1( editor ) );
editor.commands.add( 'heading6', new Heading6( editor ) );
}

return VirtualTestEditor
Expand Down
10 changes: 5 additions & 5 deletions tests/blockautoformatengine.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import VirtualTestEditor from '@ckeditor/ckeditor5-core/tests/_utils/virtualtest
import Enter from '@ckeditor/ckeditor5-enter/src/enter';
import { setData, getData } from '@ckeditor/ckeditor5-engine/src/dev-utils/model';
import testUtils from '@ckeditor/ckeditor5-core/tests/_utils/utils';
import Command from '@ckeditor/ckeditor5-core/src/command/command';
import Command from '@ckeditor/ckeditor5-core/src/command';

testUtils.createSinonSandbox();

Expand All @@ -30,7 +30,7 @@ describe( 'BlockAutoformatEngine', () => {
describe( 'Command name', () => {
it( 'should run a command when the pattern is matched', () => {
const spy = testUtils.sinon.spy();
editor.commands.set( 'testCommand', new TestCommand( editor, spy ) );
editor.commands.add( 'testCommand', new TestCommand( editor, spy ) );
new BlockAutoformatEngine( editor, /^[*]\s$/, 'testCommand' ); // eslint-disable-line no-new

setData( doc, '<paragraph>*[]</paragraph>' );
Expand All @@ -43,7 +43,7 @@ describe( 'BlockAutoformatEngine', () => {

it( 'should remove found pattern', () => {
const spy = testUtils.sinon.spy();
editor.commands.set( 'testCommand', new TestCommand( editor, spy ) );
editor.commands.add( 'testCommand', new TestCommand( editor, spy ) );
new BlockAutoformatEngine( editor, /^[*]\s$/, 'testCommand' ); // eslint-disable-line no-new

setData( doc, '<paragraph>*[]</paragraph>' );
Expand Down Expand Up @@ -103,7 +103,7 @@ class TestCommand extends Command {
* Creates an instance of the command.
*
* @param {module:core/editor~Editor} editor Editor instance.
* @param {Function} onExecuteCallback _doExecute call hook
* @param {Function} onExecuteCallback execute call hook
*/
constructor( editor, onExecuteCallback ) {
super( editor );
Expand All @@ -116,7 +116,7 @@ class TestCommand extends Command {
*
* @protected
*/
_doExecute() {
execute() {
this.onExecute();
}
}

0 comments on commit f20ef7d

Please sign in to comment.