|
@@ -22,7 +22,8 @@ describe( 'DeleteCommand', () => {
|
|
|
const command = new DeleteCommand( editor, 'backward' );
|
|
const command = new DeleteCommand( editor, 'backward' );
|
|
|
editor.commands.add( 'delete', command );
|
|
editor.commands.add( 'delete', command );
|
|
|
|
|
|
|
|
- doc.schema.registerItem( 'p', '$block' );
|
|
|
|
|
|
|
+ doc.schema.registerItem( 'paragraph', '$block' );
|
|
|
|
|
+ doc.schema.registerItem( 'heading1', '$block' );
|
|
|
} );
|
|
} );
|
|
|
} );
|
|
} );
|
|
|
|
|
|
|
@@ -38,7 +39,7 @@ describe( 'DeleteCommand', () => {
|
|
|
|
|
|
|
|
describe( 'execute()', () => {
|
|
describe( 'execute()', () => {
|
|
|
it( 'uses enqueueChanges', () => {
|
|
it( 'uses enqueueChanges', () => {
|
|
|
- setData( doc, '<p>foo[]bar</p>' );
|
|
|
|
|
|
|
+ setData( doc, '<paragraph>foo[]bar</paragraph>' );
|
|
|
|
|
|
|
|
const spy = testUtils.sinon.spy( doc, 'enqueueChanges' );
|
|
const spy = testUtils.sinon.spy( doc, 'enqueueChanges' );
|
|
|
|
|
|
|
@@ -48,7 +49,7 @@ describe( 'DeleteCommand', () => {
|
|
|
} );
|
|
} );
|
|
|
|
|
|
|
|
it( 'locks buffer when executing', () => {
|
|
it( 'locks buffer when executing', () => {
|
|
|
- setData( doc, '<p>foo[]bar</p>' );
|
|
|
|
|
|
|
+ setData( doc, '<paragraph>foo[]bar</paragraph>' );
|
|
|
|
|
|
|
|
const buffer = editor.commands.get( 'delete' )._buffer;
|
|
const buffer = editor.commands.get( 'delete' )._buffer;
|
|
|
const lockSpy = testUtils.sinon.spy( buffer, 'lock' );
|
|
const lockSpy = testUtils.sinon.spy( buffer, 'lock' );
|
|
@@ -61,38 +62,38 @@ describe( 'DeleteCommand', () => {
|
|
|
} );
|
|
} );
|
|
|
|
|
|
|
|
it( 'deletes previous character when selection is collapsed', () => {
|
|
it( 'deletes previous character when selection is collapsed', () => {
|
|
|
- setData( doc, '<p>foo[]bar</p>' );
|
|
|
|
|
|
|
+ setData( doc, '<paragraph>foo[]bar</paragraph>' );
|
|
|
|
|
|
|
|
editor.execute( 'delete' );
|
|
editor.execute( 'delete' );
|
|
|
|
|
|
|
|
- expect( getData( doc, { selection: true } ) ).to.equal( '<p>fo[]bar</p>' );
|
|
|
|
|
|
|
+ expect( getData( doc, { selection: true } ) ).to.equal( '<paragraph>fo[]bar</paragraph>' );
|
|
|
} );
|
|
} );
|
|
|
|
|
|
|
|
it( 'deletes selection contents', () => {
|
|
it( 'deletes selection contents', () => {
|
|
|
- setData( doc, '<p>fo[ob]ar</p>' );
|
|
|
|
|
|
|
+ setData( doc, '<paragraph>fo[ob]ar</paragraph>' );
|
|
|
|
|
|
|
|
editor.execute( 'delete' );
|
|
editor.execute( 'delete' );
|
|
|
|
|
|
|
|
- expect( getData( doc, { selection: true } ) ).to.equal( '<p>fo[]ar</p>' );
|
|
|
|
|
|
|
+ expect( getData( doc, { selection: true } ) ).to.equal( '<paragraph>fo[]ar</paragraph>' );
|
|
|
} );
|
|
} );
|
|
|
|
|
|
|
|
it( 'merges elements', () => {
|
|
it( 'merges elements', () => {
|
|
|
- setData( doc, '<p>foo</p><p>[]bar</p>' );
|
|
|
|
|
|
|
+ setData( doc, '<paragraph>foo</paragraph><paragraph>[]bar</paragraph>' );
|
|
|
|
|
|
|
|
editor.execute( 'delete' );
|
|
editor.execute( 'delete' );
|
|
|
|
|
|
|
|
- expect( getData( doc, { selection: true } ) ).to.equal( '<p>foo[]bar</p>' );
|
|
|
|
|
|
|
+ expect( getData( doc, { selection: true } ) ).to.equal( '<paragraph>foo[]bar</paragraph>' );
|
|
|
} );
|
|
} );
|
|
|
|
|
|
|
|
it( 'does not try to delete when selection is at the boundary', () => {
|
|
it( 'does not try to delete when selection is at the boundary', () => {
|
|
|
const spy = sinon.spy();
|
|
const spy = sinon.spy();
|
|
|
|
|
|
|
|
editor.data.on( 'deleteContent', spy );
|
|
editor.data.on( 'deleteContent', spy );
|
|
|
- setData( doc, '<p>[]foo</p>' );
|
|
|
|
|
|
|
+ setData( doc, '<paragraph>[]foo</paragraph>' );
|
|
|
|
|
|
|
|
editor.execute( 'delete' );
|
|
editor.execute( 'delete' );
|
|
|
|
|
|
|
|
- expect( getData( doc, { selection: true } ) ).to.equal( '<p>[]foo</p>' );
|
|
|
|
|
|
|
+ expect( getData( doc, { selection: true } ) ).to.equal( '<paragraph>[]foo</paragraph>' );
|
|
|
expect( spy.callCount ).to.equal( 0 );
|
|
expect( spy.callCount ).to.equal( 0 );
|
|
|
} );
|
|
} );
|
|
|
|
|
|
|
@@ -100,7 +101,7 @@ describe( 'DeleteCommand', () => {
|
|
|
const spy = sinon.spy();
|
|
const spy = sinon.spy();
|
|
|
|
|
|
|
|
editor.data.on( 'modifySelection', spy );
|
|
editor.data.on( 'modifySelection', spy );
|
|
|
- setData( doc, '<p>foo[]bar</p>' );
|
|
|
|
|
|
|
+ setData( doc, '<paragraph>foo[]bar</paragraph>' );
|
|
|
|
|
|
|
|
editor.commands.get( 'delete' ).direction = 'forward';
|
|
editor.commands.get( 'delete' ).direction = 'forward';
|
|
|
|
|
|
|
@@ -112,5 +113,86 @@ describe( 'DeleteCommand', () => {
|
|
|
expect( modifyOpts ).to.have.property( 'direction', 'forward' );
|
|
expect( modifyOpts ).to.have.property( 'direction', 'forward' );
|
|
|
expect( modifyOpts ).to.have.property( 'unit', 'word' );
|
|
expect( modifyOpts ).to.have.property( 'unit', 'word' );
|
|
|
} );
|
|
} );
|
|
|
|
|
+
|
|
|
|
|
+ it( 'leaves an empty paragraph after removing the whole content from editor', () => {
|
|
|
|
|
+ setData( doc, '<heading1>[Header 1</heading1><paragraph>Some text.]</paragraph>' );
|
|
|
|
|
+
|
|
|
|
|
+ editor.execute( 'delete' );
|
|
|
|
|
+
|
|
|
|
|
+ expect( getData( doc, { selection: true } ) ).to.equal( '<paragraph>[]</paragraph>' );
|
|
|
|
|
+ } );
|
|
|
|
|
+
|
|
|
|
|
+ it( 'leaves an empty paragraph after removing the whole content inside limit element', () => {
|
|
|
|
|
+ doc.schema.registerItem( 'section', '$root' );
|
|
|
|
|
+ doc.schema.limits.add( 'section' );
|
|
|
|
|
+ doc.schema.allow( { name: 'section', inside: '$root' } );
|
|
|
|
|
+
|
|
|
|
|
+ setData( doc,
|
|
|
|
|
+ '<heading1>Foo</heading1>' +
|
|
|
|
|
+ '<section>' +
|
|
|
|
|
+ '<heading1>[Header 1</heading1>' +
|
|
|
|
|
+ '<paragraph>Some text.]</paragraph>' +
|
|
|
|
|
+ '</section>' +
|
|
|
|
|
+ '<paragraph>Bar.</paragraph>'
|
|
|
|
|
+ );
|
|
|
|
|
+
|
|
|
|
|
+ editor.execute( 'delete' );
|
|
|
|
|
+
|
|
|
|
|
+ expect( getData( doc, { selection: true } ) ).to.equal(
|
|
|
|
|
+ '<heading1>Foo</heading1>' +
|
|
|
|
|
+ '<section>' +
|
|
|
|
|
+ '<paragraph>[]</paragraph>' +
|
|
|
|
|
+ '</section>' +
|
|
|
|
|
+ '<paragraph>Bar.</paragraph>'
|
|
|
|
|
+ );
|
|
|
|
|
+ } );
|
|
|
|
|
+
|
|
|
|
|
+ it( 'leaves an empty paragraph after removing the whole content when root element was not added as Schema.limits', () => {
|
|
|
|
|
+ doc.schema.limits.delete( '$root' );
|
|
|
|
|
+
|
|
|
|
|
+ setData( doc, '<heading1>[]</heading1>' );
|
|
|
|
|
+
|
|
|
|
|
+ editor.execute( 'delete' );
|
|
|
|
|
+
|
|
|
|
|
+ expect( getData( doc ) ).to.equal( '<paragraph>[]</paragraph>' );
|
|
|
|
|
+ } );
|
|
|
|
|
+
|
|
|
|
|
+ it( 'replaces an empty element with paragraph', () => {
|
|
|
|
|
+ setData( doc, '<heading1>[]</heading1>' );
|
|
|
|
|
+
|
|
|
|
|
+ editor.execute( 'delete' );
|
|
|
|
|
+
|
|
|
|
|
+ expect( getData( doc, { selection: true } ) ).to.equal( '<paragraph>[]</paragraph>' );
|
|
|
|
|
+ } );
|
|
|
|
|
+
|
|
|
|
|
+ it( 'does not replace an element when Backspace or Delete key is held', () => {
|
|
|
|
|
+ setData( doc, '<heading1>Bar[]</heading1>' );
|
|
|
|
|
+
|
|
|
|
|
+ for ( let sequence = 1; sequence < 10; ++sequence ) {
|
|
|
|
|
+ editor.execute( 'delete', { sequence } );
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ expect( getData( doc, { selection: true } ) ).to.equal( '<heading1>[]</heading1>' );
|
|
|
|
|
+ } );
|
|
|
|
|
+
|
|
|
|
|
+ it( 'does not replace an element if a paragraph is a common ancestor', () => {
|
|
|
|
|
+ setData( doc, '<paragraph>[]</paragraph>' );
|
|
|
|
|
+
|
|
|
|
|
+ const element = doc.selection.getFirstRange().getCommonAncestor();
|
|
|
|
|
+
|
|
|
|
|
+ editor.execute( 'delete' );
|
|
|
|
|
+
|
|
|
|
|
+ expect( element ).is.equal( doc.selection.getFirstRange().getCommonAncestor() );
|
|
|
|
|
+ } );
|
|
|
|
|
+
|
|
|
|
|
+ it( 'does not replace an element if a paragraph is not allowed in current position', () => {
|
|
|
|
|
+ doc.schema.disallow( { name: 'paragraph', inside: '$root' } );
|
|
|
|
|
+
|
|
|
|
|
+ setData( doc, '<heading1>[]</heading1>' );
|
|
|
|
|
+
|
|
|
|
|
+ editor.execute( 'delete' );
|
|
|
|
|
+
|
|
|
|
|
+ expect( getData( doc, { selection: true } ) ).to.equal( '<heading1>[]</heading1>' );
|
|
|
|
|
+ } );
|
|
|
} );
|
|
} );
|
|
|
} );
|
|
} );
|