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

Commit

Permalink
Merge pull request #225 from ckeditor/i/6356
Browse files Browse the repository at this point in the history
Other: `DeleteCommand` should pass its direction to `Model#deleteContent()`. Closes ckeditor/ckeditor5#6355. See ckeditor/ckeditor5#6356.
  • Loading branch information
Reinmar committed Mar 4, 2020
2 parents ec81ed4 + 7de78ad commit cb75e45
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 1 deletion.
6 changes: 5 additions & 1 deletion src/deletecommand.js
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,11 @@ export default class DeleteCommand extends Command {
);
} );

model.deleteContent( selection, { doNotResetEntireContent } );
model.deleteContent( selection, {
doNotResetEntireContent,
direction: this.direction
} );

this._buffer.input( changeCount );

writer.setSelection( selection );
Expand Down
23 changes: 23 additions & 0 deletions tests/deletecommand.js
Original file line number Diff line number Diff line change
Expand Up @@ -184,6 +184,29 @@ describe( 'DeleteCommand', () => {
expect( deleteOpts ).to.have.property( 'doNotResetEntireContent', false );
} );

it( 'should pass the "direction" option to Model#deleteContent method', () => {
const spy = sinon.spy();
const forwardCommand = new DeleteCommand( editor, 'forward' );
editor.commands.add( 'forwardDelete', forwardCommand );

editor.model.on( 'deleteContent', spy );
setData( model, '<paragraph>foo[]bar</paragraph>' );

editor.execute( 'delete' );

expect( spy.callCount ).to.equal( 1 );

let deleteOpts = spy.args[ 0 ][ 1 ][ 1 ];
expect( deleteOpts ).to.have.property( 'direction', 'backward' );

editor.execute( 'forwardDelete' );

expect( spy.callCount ).to.equal( 2 );

deleteOpts = spy.args[ 1 ][ 1 ][ 1 ];
expect( deleteOpts ).to.have.property( 'direction', 'forward' );
} );

it( 'leaves an empty paragraph after removing the whole content from editor', () => {
setData( model, '<heading1>[Header 1</heading1><paragraph>Some text.]</paragraph>' );

Expand Down

0 comments on commit cb75e45

Please sign in to comment.