|
|
@@ -422,6 +422,134 @@ describe( 'Autoformat', () => {
|
|
|
expect( getData( model ) ).to.equal( '<paragraph>**foobar**[]</paragraph>' );
|
|
|
} );
|
|
|
|
|
|
+ describe( 'with code element', () => {
|
|
|
+ it( 'should not format inside', () => {
|
|
|
+ // Test *.
|
|
|
+ setData( model, '<paragraph><$text code="true">fo*obar[]</$text></paragraph>' );
|
|
|
+
|
|
|
+ model.change( writer => {
|
|
|
+ writer.insertText( '*', { code: true }, doc.selection.getFirstPosition() );
|
|
|
+ } );
|
|
|
+
|
|
|
+ expect( getData( model ) ).to
|
|
|
+ .equal( '<paragraph><$text code="true">fo*obar*[]</$text></paragraph>' );
|
|
|
+
|
|
|
+ // Test __.
|
|
|
+ setData( model, '<paragraph><$text code="true">fo__obar_[]</$text></paragraph>' );
|
|
|
+
|
|
|
+ model.change( writer => {
|
|
|
+ writer.insertText( '_', { code: true }, doc.selection.getFirstPosition() );
|
|
|
+ } );
|
|
|
+
|
|
|
+ expect( getData( model ) ).to
|
|
|
+ .equal( '<paragraph><$text code="true">fo__obar__[]</$text></paragraph>' );
|
|
|
+
|
|
|
+ // Test ~~.
|
|
|
+ setData( model, '<paragraph><$text code="true">fo~~obar~[]</$text></paragraph>' );
|
|
|
+
|
|
|
+ model.change( writer => {
|
|
|
+ writer.insertText( '~', { code: true }, doc.selection.getFirstPosition() );
|
|
|
+ } );
|
|
|
+
|
|
|
+ expect( getData( model ) ).to
|
|
|
+ .equal( '<paragraph><$text code="true">fo~~obar~~[]</$text></paragraph>' );
|
|
|
+
|
|
|
+ // Test `.
|
|
|
+ setData( model, '<paragraph><$text code="true">fo`obar[]</$text></paragraph>' );
|
|
|
+
|
|
|
+ model.change( writer => {
|
|
|
+ writer.insertText( '`', { code: true }, doc.selection.getFirstPosition() );
|
|
|
+ } );
|
|
|
+
|
|
|
+ expect( getData( model ) ).to
|
|
|
+ .equal( '<paragraph><$text code="true">fo`obar`[]</$text></paragraph>' );
|
|
|
+ } );
|
|
|
+
|
|
|
+ it( 'should not format across', () => {
|
|
|
+ // Test *.
|
|
|
+ setData( model, '<paragraph><$text code="true">fo*o</$text>bar[]</paragraph>' );
|
|
|
+
|
|
|
+ model.change( writer => {
|
|
|
+ writer.insertText( '*', doc.selection.getFirstPosition() );
|
|
|
+ } );
|
|
|
+
|
|
|
+ expect( getData( model ) ).to
|
|
|
+ .equal( '<paragraph><$text code="true">fo*o</$text>bar*[]</paragraph>' );
|
|
|
+
|
|
|
+ // Test __.
|
|
|
+ setData( model, '<paragraph><$text code="true">fo__o</$text>bar_[]</paragraph>' );
|
|
|
+
|
|
|
+ model.change( writer => {
|
|
|
+ writer.insertText( '_', doc.selection.getFirstPosition() );
|
|
|
+ } );
|
|
|
+
|
|
|
+ expect( getData( model ) ).to
|
|
|
+ .equal( '<paragraph><$text code="true">fo__o</$text>bar__[]</paragraph>' );
|
|
|
+
|
|
|
+ // Test ~~.
|
|
|
+ setData( model, '<paragraph><$text code="true">fo~~o</$text>bar~[]</paragraph>' );
|
|
|
+
|
|
|
+ model.change( writer => {
|
|
|
+ writer.insertText( '~', doc.selection.getFirstPosition() );
|
|
|
+ } );
|
|
|
+
|
|
|
+ expect( getData( model ) ).to
|
|
|
+ .equal( '<paragraph><$text code="true">fo~~o</$text>bar~~[]</paragraph>' );
|
|
|
+
|
|
|
+ // Test `.
|
|
|
+ setData( model, '<paragraph><$text code="true">fo`o</$text>bar[]</paragraph>' );
|
|
|
+
|
|
|
+ model.change( writer => {
|
|
|
+ writer.insertText( '`', doc.selection.getFirstPosition() );
|
|
|
+ } );
|
|
|
+
|
|
|
+ expect( getData( model ) ).to
|
|
|
+ .equal( '<paragraph><$text code="true">fo`o</$text>bar`[]</paragraph>' );
|
|
|
+ } );
|
|
|
+
|
|
|
+ it( 'should format after', () => {
|
|
|
+ // Test *.
|
|
|
+ setData( model, '<paragraph><$text code="true">fo*o</$text>b*ar[]</paragraph>' );
|
|
|
+
|
|
|
+ model.change( writer => {
|
|
|
+ writer.insertText( '*', doc.selection.getFirstPosition() );
|
|
|
+ } );
|
|
|
+
|
|
|
+ expect( getData( model ) ).to
|
|
|
+ .equal( '<paragraph><$text code="true">fo*o</$text>b<$text italic="true">ar</$text>[]</paragraph>' );
|
|
|
+
|
|
|
+ // Test __.
|
|
|
+ setData( model, '<paragraph><$text code="true">fo__o</$text>b__ar_[]</paragraph>' );
|
|
|
+
|
|
|
+ model.change( writer => {
|
|
|
+ writer.insertText( '_', doc.selection.getFirstPosition() );
|
|
|
+ } );
|
|
|
+
|
|
|
+ expect( getData( model ) ).to
|
|
|
+ .equal( '<paragraph><$text code="true">fo__o</$text>b<$text bold="true">ar</$text>[]</paragraph>' );
|
|
|
+
|
|
|
+ // Test ~~.
|
|
|
+ setData( model, '<paragraph><$text code="true">fo~~o</$text>b~~ar~[]</paragraph>' );
|
|
|
+
|
|
|
+ model.change( writer => {
|
|
|
+ writer.insertText( '~', doc.selection.getFirstPosition() );
|
|
|
+ } );
|
|
|
+
|
|
|
+ expect( getData( model ) ).to
|
|
|
+ .equal( '<paragraph><$text code="true">fo~~o</$text>b<$text strikethrough="true">ar</$text>[]</paragraph>' );
|
|
|
+
|
|
|
+ // Test `.
|
|
|
+ setData( model, '<paragraph><$text code="true">fo`o</$text>b`ar[]</paragraph>' );
|
|
|
+
|
|
|
+ model.change( writer => {
|
|
|
+ writer.insertText( '`', doc.selection.getFirstPosition() );
|
|
|
+ } );
|
|
|
+
|
|
|
+ expect( getData( model ) ).to
|
|
|
+ .equal( '<paragraph><$text code="true">fo`o</$text>b<$text code="true">ar</$text>[]</paragraph>' );
|
|
|
+ } );
|
|
|
+ } );
|
|
|
+
|
|
|
it( 'should work with <softBreak>s in paragraph', () => {
|
|
|
setData( model, '<paragraph>foo<softBreak></softBreak>**barbaz*[]</paragraph>' );
|
|
|
model.change( writer => {
|