|
|
@@ -1,17 +1,17 @@
|
|
|
/**
|
|
|
- * @license Copyright (c) 2003-2017, CKSource - Frederico Knabben. All rights reserved.
|
|
|
+ * @license Copyright (c) 2003-2018, CKSource - Frederico Knabben. All rights reserved.
|
|
|
* For licensing, see LICENSE.md.
|
|
|
*/
|
|
|
|
|
|
import Autoformat from '../src/autoformat';
|
|
|
|
|
|
import Paragraph from '@ckeditor/ckeditor5-paragraph/src/paragraph';
|
|
|
-import ListEngine from '@ckeditor/ckeditor5-list/src/listengine';
|
|
|
-import HeadingEngine from '@ckeditor/ckeditor5-heading/src/headingengine';
|
|
|
-import BoldEngine from '@ckeditor/ckeditor5-basic-styles/src/boldengine';
|
|
|
-import CodeEngine from '@ckeditor/ckeditor5-basic-styles/src/codeengine';
|
|
|
-import ItalicEngine from '@ckeditor/ckeditor5-basic-styles/src/italicengine';
|
|
|
-import BlockQuoteEngine from '@ckeditor/ckeditor5-block-quote/src/blockquoteengine';
|
|
|
+import ListEditing from '@ckeditor/ckeditor5-list/src/listediting';
|
|
|
+import HeadingEditing from '@ckeditor/ckeditor5-heading/src/headingediting';
|
|
|
+import BoldEditing from '@ckeditor/ckeditor5-basic-styles/src/bold/boldediting';
|
|
|
+import CodeEditing from '@ckeditor/ckeditor5-basic-styles/src/code/codeediting';
|
|
|
+import ItalicEditing from '@ckeditor/ckeditor5-basic-styles/src/italic/italicediting';
|
|
|
+import BlockQuoteEditing from '@ckeditor/ckeditor5-block-quote/src/blockquoteediting';
|
|
|
import Enter from '@ckeditor/ckeditor5-enter/src/enter';
|
|
|
|
|
|
import VirtualTestEditor from '@ckeditor/ckeditor5-core/tests/_utils/virtualtesteditor';
|
|
|
@@ -19,12 +19,12 @@ 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';
|
|
|
+import HeadingCommand from '@ckeditor/ckeditor5-heading/src/headingcommand';
|
|
|
|
|
|
testUtils.createSinonSandbox();
|
|
|
|
|
|
describe( 'Autoformat', () => {
|
|
|
- let editor, doc, batch;
|
|
|
+ let editor, model, doc;
|
|
|
|
|
|
beforeEach( () => {
|
|
|
return VirtualTestEditor
|
|
|
@@ -33,18 +33,18 @@ describe( 'Autoformat', () => {
|
|
|
Enter,
|
|
|
Paragraph,
|
|
|
Autoformat,
|
|
|
- ListEngine,
|
|
|
- HeadingEngine,
|
|
|
- BoldEngine,
|
|
|
- ItalicEngine,
|
|
|
- CodeEngine,
|
|
|
- BlockQuoteEngine
|
|
|
+ ListEditing,
|
|
|
+ HeadingEditing,
|
|
|
+ BoldEditing,
|
|
|
+ ItalicEditing,
|
|
|
+ CodeEditing,
|
|
|
+ BlockQuoteEditing
|
|
|
]
|
|
|
} )
|
|
|
.then( newEditor => {
|
|
|
editor = newEditor;
|
|
|
- doc = editor.document;
|
|
|
- batch = doc.batch();
|
|
|
+ model = editor.model;
|
|
|
+ doc = model.document;
|
|
|
} );
|
|
|
} );
|
|
|
|
|
|
@@ -54,99 +54,106 @@ describe( 'Autoformat', () => {
|
|
|
|
|
|
describe( 'Bulleted list', () => {
|
|
|
it( 'should replace asterisk with bulleted list item', () => {
|
|
|
- setData( doc, '<paragraph>*[]</paragraph>' );
|
|
|
- doc.enqueueChanges( () => {
|
|
|
- batch.insert( doc.selection.getFirstPosition(), ' ' );
|
|
|
+ setData( model, '<paragraph>*[]</paragraph>' );
|
|
|
+ model.change( writer => {
|
|
|
+ writer.insertText( ' ', doc.selection.getFirstPosition() );
|
|
|
} );
|
|
|
|
|
|
- expect( getData( doc ) ).to.equal( '<listItem indent="0" type="bulleted">[]</listItem>' );
|
|
|
+ expect( getData( model ) ).to.equal( '<listItem indent="0" type="bulleted">[]</listItem>' );
|
|
|
} );
|
|
|
|
|
|
it( 'should replace minus character with bulleted list item', () => {
|
|
|
- setData( doc, '<paragraph>-[]</paragraph>' );
|
|
|
- doc.enqueueChanges( () => {
|
|
|
- batch.insert( doc.selection.getFirstPosition(), ' ' );
|
|
|
+ setData( model, '<paragraph>-[]</paragraph>' );
|
|
|
+ model.change( writer => {
|
|
|
+ writer.insertText( ' ', doc.selection.getFirstPosition() );
|
|
|
} );
|
|
|
|
|
|
- expect( getData( doc ) ).to.equal( '<listItem indent="0" type="bulleted">[]</listItem>' );
|
|
|
+ expect( getData( model ) ).to.equal( '<listItem indent="0" type="bulleted">[]</listItem>' );
|
|
|
} );
|
|
|
|
|
|
it( 'should not replace minus character when inside bulleted list item', () => {
|
|
|
- setData( doc, '<listItem indent="0" type="bulleted">-[]</listItem>' );
|
|
|
- doc.enqueueChanges( () => {
|
|
|
- batch.insert( doc.selection.getFirstPosition(), ' ' );
|
|
|
+ setData( model, '<listItem indent="0" type="bulleted">-[]</listItem>' );
|
|
|
+ model.change( writer => {
|
|
|
+ writer.insertText( ' ', doc.selection.getFirstPosition() );
|
|
|
} );
|
|
|
|
|
|
- expect( getData( doc ) ).to.equal( '<listItem indent="0" type="bulleted">- []</listItem>' );
|
|
|
+ expect( getData( model ) ).to.equal( '<listItem indent="0" type="bulleted">- []</listItem>' );
|
|
|
} );
|
|
|
} );
|
|
|
|
|
|
describe( 'Numbered list', () => {
|
|
|
- it( 'should replace digit with numbered list item', () => {
|
|
|
- setData( doc, '<paragraph>1.[]</paragraph>' );
|
|
|
- doc.enqueueChanges( () => {
|
|
|
- batch.insert( doc.selection.getFirstPosition(), ' ' );
|
|
|
+ it( 'should replace digit with numbered list item using the dot format', () => {
|
|
|
+ setData( model, '<paragraph>1.[]</paragraph>' );
|
|
|
+ model.change( writer => {
|
|
|
+ writer.insertText( ' ', doc.selection.getFirstPosition() );
|
|
|
} );
|
|
|
|
|
|
- expect( getData( doc ) ).to.equal( '<listItem indent="0" type="numbered">[]</listItem>' );
|
|
|
+ expect( getData( model ) ).to.equal( '<listItem indent="0" type="numbered">[]</listItem>' );
|
|
|
+ } );
|
|
|
+
|
|
|
+ it( 'should replace digit with numbered list item using the parenthesis format', () => {
|
|
|
+ setData( model, '<paragraph>1)[]</paragraph>' );
|
|
|
+ model.change( writer => {
|
|
|
+ writer.insertText( ' ', doc.selection.getFirstPosition() );
|
|
|
+ } );
|
|
|
+
|
|
|
+ expect( getData( model ) ).to.equal( '<listItem indent="0" type="numbered">[]</listItem>' );
|
|
|
+ } );
|
|
|
+
|
|
|
+ it( 'should not replace digit character when there is no . or ) in the format', () => {
|
|
|
+ setData( model, '<paragraph>1[]</paragraph>' );
|
|
|
+ model.change( writer => {
|
|
|
+ writer.insertText( ' ', doc.selection.getFirstPosition() );
|
|
|
+ } );
|
|
|
+
|
|
|
+ expect( getData( model ) ).to.equal( '<paragraph>1 []</paragraph>' );
|
|
|
} );
|
|
|
|
|
|
it( 'should not replace digit character when inside numbered list item', () => {
|
|
|
- setData( doc, '<listItem indent="0" type="numbered">1.[]</listItem>' );
|
|
|
- doc.enqueueChanges( () => {
|
|
|
- batch.insert( doc.selection.getFirstPosition(), ' ' );
|
|
|
+ setData( model, '<listItem indent="0" type="numbered">1.[]</listItem>' );
|
|
|
+ model.change( writer => {
|
|
|
+ writer.insertText( ' ', doc.selection.getFirstPosition() );
|
|
|
} );
|
|
|
|
|
|
- expect( getData( doc ) ).to.equal( '<listItem indent="0" type="numbered">1. []</listItem>' );
|
|
|
+ expect( getData( model ) ).to.equal( '<listItem indent="0" type="numbered">1. []</listItem>' );
|
|
|
} );
|
|
|
} );
|
|
|
|
|
|
describe( 'Heading', () => {
|
|
|
it( 'should replace hash character with heading', () => {
|
|
|
- setData( doc, '<paragraph>#[]</paragraph>' );
|
|
|
- doc.enqueueChanges( () => {
|
|
|
- batch.insert( doc.selection.getFirstPosition(), ' ' );
|
|
|
+ setData( model, '<paragraph>#[]</paragraph>' );
|
|
|
+ model.change( writer => {
|
|
|
+ writer.insertText( ' ', doc.selection.getFirstPosition() );
|
|
|
} );
|
|
|
|
|
|
- expect( getData( doc ) ).to.equal( '<heading1>[]</heading1>' );
|
|
|
+ expect( getData( model ) ).to.equal( '<heading1>[]</heading1>' );
|
|
|
} );
|
|
|
|
|
|
it( 'should replace two hash characters with heading level 2', () => {
|
|
|
- setData( doc, '<paragraph>##[]</paragraph>' );
|
|
|
- doc.enqueueChanges( () => {
|
|
|
- batch.insert( doc.selection.getFirstPosition(), ' ' );
|
|
|
+ setData( model, '<paragraph>##[]</paragraph>' );
|
|
|
+ model.change( writer => {
|
|
|
+ writer.insertText( ' ', doc.selection.getFirstPosition() );
|
|
|
} );
|
|
|
|
|
|
- expect( getData( doc ) ).to.equal( '<heading2>[]</heading2>' );
|
|
|
+ expect( getData( model ) ).to.equal( '<heading2>[]</heading2>' );
|
|
|
} );
|
|
|
|
|
|
it( 'should not replace hash character when inside heading', () => {
|
|
|
- setData( doc, '<heading1>#[]</heading1>' );
|
|
|
- doc.enqueueChanges( () => {
|
|
|
- batch.insert( doc.selection.getFirstPosition(), ' ' );
|
|
|
+ setData( model, '<heading1>#[]</heading1>' );
|
|
|
+ model.change( writer => {
|
|
|
+ writer.insertText( ' ', doc.selection.getFirstPosition() );
|
|
|
} );
|
|
|
|
|
|
- expect( getData( doc ) ).to.equal( '<heading1># []</heading1>' );
|
|
|
+ expect( getData( model ) ).to.equal( '<heading1># []</heading1>' );
|
|
|
} );
|
|
|
|
|
|
it( 'should work with heading1-heading6 commands regardless of the config of the heading feature', () => {
|
|
|
- const spy1 = sinon.spy();
|
|
|
- const spy6 = sinon.spy();
|
|
|
+ const command = new HeadingCommand( editor, [ 'heading1', 'heading6' ] );
|
|
|
|
|
|
- class Heading6 extends Command {
|
|
|
- execute() {
|
|
|
- spy6();
|
|
|
- }
|
|
|
- }
|
|
|
- class Heading1 extends Command {
|
|
|
- execute() {
|
|
|
- spy1();
|
|
|
- }
|
|
|
- }
|
|
|
+ const spy = sinon.spy( command, 'execute' );
|
|
|
|
|
|
function HeadingPlugin( editor ) {
|
|
|
- editor.commands.add( 'heading1', new Heading1( editor ) );
|
|
|
- editor.commands.add( 'heading6', new Heading6( editor ) );
|
|
|
+ editor.commands.add( 'heading', command );
|
|
|
}
|
|
|
|
|
|
return VirtualTestEditor
|
|
|
@@ -156,21 +163,26 @@ describe( 'Autoformat', () => {
|
|
|
]
|
|
|
} )
|
|
|
.then( editor => {
|
|
|
- const doc = editor.document;
|
|
|
+ const model = editor.model;
|
|
|
+ const doc = model.document;
|
|
|
|
|
|
- setData( doc, '<paragraph>#[]</paragraph>' );
|
|
|
- doc.enqueueChanges( () => {
|
|
|
- doc.batch().insert( doc.selection.getFirstPosition(), ' ' );
|
|
|
+ setData( model, '<paragraph>#[]</paragraph>' );
|
|
|
+ model.change( writer => {
|
|
|
+ writer.insertText( ' ', doc.selection.getFirstPosition() );
|
|
|
} );
|
|
|
|
|
|
- expect( spy1.calledOnce ).to.be.true;
|
|
|
+ sinon.assert.calledOnce( spy );
|
|
|
+ sinon.assert.calledWithExactly( spy, { value: 'heading1' } );
|
|
|
+
|
|
|
+ spy.resetHistory();
|
|
|
|
|
|
- setData( doc, '<paragraph>######[]</paragraph>' );
|
|
|
- doc.enqueueChanges( () => {
|
|
|
- doc.batch().insert( doc.selection.getFirstPosition(), ' ' );
|
|
|
+ setData( model, '<paragraph>######[]</paragraph>' );
|
|
|
+ model.change( writer => {
|
|
|
+ writer.insertText( ' ', doc.selection.getFirstPosition() );
|
|
|
} );
|
|
|
|
|
|
- expect( spy6.calledOnce ).to.be.true;
|
|
|
+ sinon.assert.calledOnce( spy );
|
|
|
+ sinon.assert.calledWithExactly( spy, { value: 'heading6' } );
|
|
|
|
|
|
return editor.destroy();
|
|
|
} );
|
|
|
@@ -178,87 +190,87 @@ describe( 'Autoformat', () => {
|
|
|
} );
|
|
|
|
|
|
describe( 'Block quote', () => {
|
|
|
- it( 'should replace greater-than character with heading', () => {
|
|
|
- setData( doc, '<paragraph>>[]</paragraph>' );
|
|
|
- doc.enqueueChanges( () => {
|
|
|
- batch.insert( doc.selection.getFirstPosition(), ' ' );
|
|
|
+ it( 'should replace greater-than character with block quote', () => {
|
|
|
+ setData( model, '<paragraph>>[]</paragraph>' );
|
|
|
+ model.change( writer => {
|
|
|
+ writer.insertText( ' ', doc.selection.getFirstPosition() );
|
|
|
} );
|
|
|
|
|
|
- expect( getData( doc ) ).to.equal( '<blockQuote><paragraph>[]</paragraph></blockQuote>' );
|
|
|
+ expect( getData( model ) ).to.equal( '<blockQuote><paragraph>[]</paragraph></blockQuote>' );
|
|
|
} );
|
|
|
|
|
|
it( 'should not replace greater-than character when inside heading', () => {
|
|
|
- setData( doc, '<heading1>>[]</heading1>' );
|
|
|
- doc.enqueueChanges( () => {
|
|
|
- batch.insert( doc.selection.getFirstPosition(), ' ' );
|
|
|
+ setData( model, '<heading1>>[]</heading1>' );
|
|
|
+ model.change( writer => {
|
|
|
+ writer.insertText( ' ', doc.selection.getFirstPosition() );
|
|
|
} );
|
|
|
|
|
|
- expect( getData( doc ) ).to.equal( '<heading1>> []</heading1>' );
|
|
|
+ expect( getData( model ) ).to.equal( '<heading1>> []</heading1>' );
|
|
|
} );
|
|
|
|
|
|
it( 'should not replace greater-than character when inside numbered list', () => {
|
|
|
- setData( doc, '<listItem indent="0" type="numbered">1. >[]</listItem>' );
|
|
|
- doc.enqueueChanges( () => {
|
|
|
- batch.insert( doc.selection.getFirstPosition(), ' ' );
|
|
|
+ setData( model, '<listItem indent="0" type="numbered">1. >[]</listItem>' );
|
|
|
+ model.change( writer => {
|
|
|
+ writer.insertText( ' ', doc.selection.getFirstPosition() );
|
|
|
} );
|
|
|
|
|
|
- expect( getData( doc ) ).to.equal( '<listItem indent="0" type="numbered">1. > []</listItem>' );
|
|
|
+ expect( getData( model ) ).to.equal( '<listItem indent="0" type="numbered">1. > []</listItem>' );
|
|
|
} );
|
|
|
|
|
|
it( 'should not replace greater-than character when inside buletted list', () => {
|
|
|
- setData( doc, '<listItem indent="0" type="bulleted">1. >[]</listItem>' );
|
|
|
- doc.enqueueChanges( () => {
|
|
|
- batch.insert( doc.selection.getFirstPosition(), ' ' );
|
|
|
+ setData( model, '<listItem indent="0" type="bulleted">1. >[]</listItem>' );
|
|
|
+ model.change( writer => {
|
|
|
+ writer.insertText( ' ', doc.selection.getFirstPosition() );
|
|
|
} );
|
|
|
|
|
|
- expect( getData( doc ) ).to.equal( '<listItem indent="0" type="bulleted">1. > []</listItem>' );
|
|
|
+ expect( getData( model ) ).to.equal( '<listItem indent="0" type="bulleted">1. > []</listItem>' );
|
|
|
} );
|
|
|
} );
|
|
|
|
|
|
describe( 'Inline autoformat', () => {
|
|
|
it( 'should replace both "**" with bold', () => {
|
|
|
- setData( doc, '<paragraph>**foobar*[]</paragraph>' );
|
|
|
- doc.enqueueChanges( () => {
|
|
|
- batch.insert( doc.selection.getFirstPosition(), '*' );
|
|
|
+ setData( model, '<paragraph>**foobar*[]</paragraph>' );
|
|
|
+ model.change( writer => {
|
|
|
+ writer.insertText( '*', doc.selection.getFirstPosition() );
|
|
|
} );
|
|
|
|
|
|
- expect( getData( doc ) ).to.equal( '<paragraph><$text bold="true">foobar</$text>[]</paragraph>' );
|
|
|
+ expect( getData( model ) ).to.equal( '<paragraph><$text bold="true">foobar</$text>[]</paragraph>' );
|
|
|
} );
|
|
|
|
|
|
it( 'should replace both "*" with italic', () => {
|
|
|
- setData( doc, '<paragraph>*foobar[]</paragraph>' );
|
|
|
- doc.enqueueChanges( () => {
|
|
|
- batch.insert( doc.selection.getFirstPosition(), '*' );
|
|
|
+ setData( model, '<paragraph>*foobar[]</paragraph>' );
|
|
|
+ model.change( writer => {
|
|
|
+ writer.insertText( '*', doc.selection.getFirstPosition() );
|
|
|
} );
|
|
|
|
|
|
- expect( getData( doc ) ).to.equal( '<paragraph><$text italic="true">foobar</$text>[]</paragraph>' );
|
|
|
+ expect( getData( model ) ).to.equal( '<paragraph><$text italic="true">foobar</$text>[]</paragraph>' );
|
|
|
} );
|
|
|
|
|
|
it( 'should replace both "`" with code', () => {
|
|
|
- setData( doc, '<paragraph>`foobar[]</paragraph>' );
|
|
|
- doc.enqueueChanges( () => {
|
|
|
- batch.insert( doc.selection.getFirstPosition(), '`' );
|
|
|
+ setData( model, '<paragraph>`foobar[]</paragraph>' );
|
|
|
+ model.change( writer => {
|
|
|
+ writer.insertText( '`', doc.selection.getFirstPosition() );
|
|
|
} );
|
|
|
|
|
|
- expect( getData( doc ) ).to.equal( '<paragraph><$text code="true">foobar</$text>[]</paragraph>' );
|
|
|
+ expect( getData( model ) ).to.equal( '<paragraph><$text code="true">foobar</$text>[]</paragraph>' );
|
|
|
} );
|
|
|
|
|
|
it( 'nothing should be replaces when typing "*"', () => {
|
|
|
- setData( doc, '<paragraph>foobar[]</paragraph>' );
|
|
|
- doc.enqueueChanges( () => {
|
|
|
- batch.insert( doc.selection.getFirstPosition(), '*' );
|
|
|
+ setData( model, '<paragraph>foobar[]</paragraph>' );
|
|
|
+ model.change( writer => {
|
|
|
+ writer.insertText( '*', doc.selection.getFirstPosition() );
|
|
|
} );
|
|
|
|
|
|
- expect( getData( doc ) ).to.equal( '<paragraph>foobar*[]</paragraph>' );
|
|
|
+ expect( getData( model ) ).to.equal( '<paragraph>foobar*[]</paragraph>' );
|
|
|
} );
|
|
|
|
|
|
it( 'should format inside the text', () => {
|
|
|
- setData( doc, '<paragraph>foo **bar*[] baz</paragraph>' );
|
|
|
- doc.enqueueChanges( () => {
|
|
|
- batch.insert( doc.selection.getFirstPosition(), '*' );
|
|
|
+ setData( model, '<paragraph>foo **bar*[] baz</paragraph>' );
|
|
|
+ model.change( writer => {
|
|
|
+ writer.insertText( '*', doc.selection.getFirstPosition() );
|
|
|
} );
|
|
|
|
|
|
- expect( getData( doc ) ).to.equal( '<paragraph>foo <$text bold="true">bar</$text>[] baz</paragraph>' );
|
|
|
+ expect( getData( model ) ).to.equal( '<paragraph>foo <$text bold="true">bar</$text>[] baz</paragraph>' );
|
|
|
} );
|
|
|
} );
|
|
|
|
|
|
@@ -270,113 +282,113 @@ describe( 'Autoformat', () => {
|
|
|
} )
|
|
|
.then( newEditor => {
|
|
|
editor = newEditor;
|
|
|
- doc = editor.document;
|
|
|
- batch = doc.batch();
|
|
|
+ model = editor.model;
|
|
|
+ doc = model.document;
|
|
|
} );
|
|
|
} );
|
|
|
|
|
|
it( 'should not replace asterisk with bulleted list item', () => {
|
|
|
- setData( doc, '<paragraph>*[]</paragraph>' );
|
|
|
- doc.enqueueChanges( () => {
|
|
|
- batch.insert( doc.selection.getFirstPosition(), ' ' );
|
|
|
+ setData( model, '<paragraph>*[]</paragraph>' );
|
|
|
+ model.change( writer => {
|
|
|
+ writer.insertText( ' ', doc.selection.getFirstPosition() );
|
|
|
} );
|
|
|
|
|
|
- expect( getData( doc ) ).to.equal( '<paragraph>* []</paragraph>' );
|
|
|
+ expect( getData( model ) ).to.equal( '<paragraph>* []</paragraph>' );
|
|
|
} );
|
|
|
|
|
|
it( 'should not replace minus character with bulleted list item', () => {
|
|
|
- setData( doc, '<paragraph>-[]</paragraph>' );
|
|
|
- doc.enqueueChanges( () => {
|
|
|
- batch.insert( doc.selection.getFirstPosition(), ' ' );
|
|
|
+ setData( model, '<paragraph>-[]</paragraph>' );
|
|
|
+ model.change( writer => {
|
|
|
+ writer.insertText( ' ', doc.selection.getFirstPosition() );
|
|
|
} );
|
|
|
|
|
|
- expect( getData( doc ) ).to.equal( '<paragraph>- []</paragraph>' );
|
|
|
+ expect( getData( model ) ).to.equal( '<paragraph>- []</paragraph>' );
|
|
|
} );
|
|
|
|
|
|
it( 'should not replace digit with numbered list item', () => {
|
|
|
- setData( doc, '<paragraph>1.[]</paragraph>' );
|
|
|
- doc.enqueueChanges( () => {
|
|
|
- batch.insert( doc.selection.getFirstPosition(), ' ' );
|
|
|
+ setData( model, '<paragraph>1.[]</paragraph>' );
|
|
|
+ model.change( writer => {
|
|
|
+ writer.insertText( ' ', doc.selection.getFirstPosition() );
|
|
|
} );
|
|
|
|
|
|
- expect( getData( doc ) ).to.equal( '<paragraph>1. []</paragraph>' );
|
|
|
+ expect( getData( model ) ).to.equal( '<paragraph>1. []</paragraph>' );
|
|
|
} );
|
|
|
|
|
|
it( 'should not replace hash character with heading', () => {
|
|
|
- setData( doc, '<paragraph>#[]</paragraph>' );
|
|
|
- doc.enqueueChanges( () => {
|
|
|
- batch.insert( doc.selection.getFirstPosition(), ' ' );
|
|
|
+ setData( model, '<paragraph>#[]</paragraph>' );
|
|
|
+ model.change( writer => {
|
|
|
+ writer.insertText( ' ', doc.selection.getFirstPosition() );
|
|
|
} );
|
|
|
|
|
|
- expect( getData( doc ) ).to.equal( '<paragraph># []</paragraph>' );
|
|
|
+ expect( getData( model ) ).to.equal( '<paragraph># []</paragraph>' );
|
|
|
} );
|
|
|
|
|
|
it( 'should not replace two hash characters with heading level 2', () => {
|
|
|
- setData( doc, '<paragraph>##[]</paragraph>' );
|
|
|
- doc.enqueueChanges( () => {
|
|
|
- batch.insert( doc.selection.getFirstPosition(), ' ' );
|
|
|
+ setData( model, '<paragraph>##[]</paragraph>' );
|
|
|
+ model.change( writer => {
|
|
|
+ writer.insertText( ' ', doc.selection.getFirstPosition() );
|
|
|
} );
|
|
|
|
|
|
- expect( getData( doc ) ).to.equal( '<paragraph>## []</paragraph>' );
|
|
|
+ expect( getData( model ) ).to.equal( '<paragraph>## []</paragraph>' );
|
|
|
} );
|
|
|
|
|
|
it( 'should not replace both "**" with bold', () => {
|
|
|
- setData( doc, '<paragraph>**foobar*[]</paragraph>' );
|
|
|
- doc.enqueueChanges( () => {
|
|
|
- batch.insert( doc.selection.getFirstPosition(), '*' );
|
|
|
+ setData( model, '<paragraph>**foobar*[]</paragraph>' );
|
|
|
+ model.change( writer => {
|
|
|
+ writer.insertText( '*', doc.selection.getFirstPosition() );
|
|
|
} );
|
|
|
|
|
|
- expect( getData( doc ) ).to.equal( '<paragraph>**foobar**[]</paragraph>' );
|
|
|
+ expect( getData( model ) ).to.equal( '<paragraph>**foobar**[]</paragraph>' );
|
|
|
} );
|
|
|
|
|
|
it( 'should not replace both "*" with italic', () => {
|
|
|
- setData( doc, '<paragraph>*foobar[]</paragraph>' );
|
|
|
- doc.enqueueChanges( () => {
|
|
|
- batch.insert( doc.selection.getFirstPosition(), '*' );
|
|
|
+ setData( model, '<paragraph>*foobar[]</paragraph>' );
|
|
|
+ model.change( writer => {
|
|
|
+ writer.insertText( '*', doc.selection.getFirstPosition() );
|
|
|
} );
|
|
|
|
|
|
- expect( getData( doc ) ).to.equal( '<paragraph>*foobar*[]</paragraph>' );
|
|
|
+ expect( getData( model ) ).to.equal( '<paragraph>*foobar*[]</paragraph>' );
|
|
|
} );
|
|
|
|
|
|
it( 'should not replace both "`" with code', () => {
|
|
|
- setData( doc, '<paragraph>`foobar[]</paragraph>' );
|
|
|
- doc.enqueueChanges( () => {
|
|
|
- batch.insert( doc.selection.getFirstPosition(), '`' );
|
|
|
+ setData( model, '<paragraph>`foobar[]</paragraph>' );
|
|
|
+ model.change( writer => {
|
|
|
+ writer.insertText( '`', doc.selection.getFirstPosition() );
|
|
|
} );
|
|
|
|
|
|
- expect( getData( doc ) ).to.equal( '<paragraph>`foobar`[]</paragraph>' );
|
|
|
+ expect( getData( model ) ).to.equal( '<paragraph>`foobar`[]</paragraph>' );
|
|
|
} );
|
|
|
|
|
|
it( 'should not replace ">" with block quote', () => {
|
|
|
- setData( doc, '<paragraph>>[]</paragraph>' );
|
|
|
- doc.enqueueChanges( () => {
|
|
|
- batch.insert( doc.selection.getFirstPosition(), ' ' );
|
|
|
+ setData( model, '<paragraph>>[]</paragraph>' );
|
|
|
+ model.change( writer => {
|
|
|
+ writer.insertText( ' ', doc.selection.getFirstPosition() );
|
|
|
} );
|
|
|
|
|
|
- expect( getData( doc ) ).to.equal( '<paragraph>> []</paragraph>' );
|
|
|
+ expect( getData( model ) ).to.equal( '<paragraph>> []</paragraph>' );
|
|
|
} );
|
|
|
|
|
|
it( 'should use only configured headings', () => {
|
|
|
return VirtualTestEditor
|
|
|
.create( {
|
|
|
- plugins: [ Enter, Paragraph, Autoformat, ListEngine, HeadingEngine ],
|
|
|
+ plugins: [ Enter, Paragraph, Autoformat, ListEditing, HeadingEditing ],
|
|
|
heading: {
|
|
|
options: [
|
|
|
- { modelElement: 'paragraph' },
|
|
|
- { modelElement: 'heading1', viewElement: 'h2' }
|
|
|
+ { model: 'paragraph' },
|
|
|
+ { model: 'heading1', view: 'h2' }
|
|
|
]
|
|
|
}
|
|
|
} )
|
|
|
.then( editor => {
|
|
|
- doc = editor.document;
|
|
|
- batch = doc.batch();
|
|
|
+ model = editor.model;
|
|
|
+ doc = model.document;
|
|
|
|
|
|
- setData( doc, '<paragraph>##[]</paragraph>' );
|
|
|
- doc.enqueueChanges( () => {
|
|
|
- batch.insert( doc.selection.getFirstPosition(), ' ' );
|
|
|
+ setData( model, '<paragraph>##[]</paragraph>' );
|
|
|
+ model.change( writer => {
|
|
|
+ writer.insertText( ' ', doc.selection.getFirstPosition() );
|
|
|
} );
|
|
|
|
|
|
- expect( getData( doc ) ).to.equal( '<paragraph>## []</paragraph>' );
|
|
|
+ expect( getData( model ) ).to.equal( '<paragraph>## []</paragraph>' );
|
|
|
} );
|
|
|
} );
|
|
|
} );
|