diff --git a/src/autoformat.js b/src/autoformat.js index b061adc..fb4a9ef 100644 --- a/src/autoformat.js +++ b/src/autoformat.js @@ -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' ); } @@ -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. `(?:^|[^\*])`). @@ -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 ]; @@ -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' ); } diff --git a/tests/autoformat.js b/tests/autoformat.js index f4fc428..2dae99b 100644 --- a/tests/autoformat.js +++ b/tests/autoformat.js @@ -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(); @@ -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 diff --git a/tests/blockautoformatengine.js b/tests/blockautoformatengine.js index 4ab088b..fe67dce 100644 --- a/tests/blockautoformatengine.js +++ b/tests/blockautoformatengine.js @@ -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(); @@ -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, '*[]' ); @@ -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, '*[]' ); @@ -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 ); @@ -116,7 +116,7 @@ class TestCommand extends Command { * * @protected */ - _doExecute() { + execute() { this.onExecute(); } }