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 #174 from ckeditor/t/suggestion-mode
Browse files Browse the repository at this point in the history
Other: Exposed DeleteCommand#buffer. InputCommand uses Model#deleteContent instead of model.Writer#remove.
  • Loading branch information
Piotr Jasiun committed Dec 21, 2018
2 parents 4ca15ac + 4b9d6ad commit 5ab39fc
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 2 deletions.
9 changes: 9 additions & 0 deletions src/deletecommand.js
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,15 @@ export default class DeleteCommand extends Command {
this._buffer = new ChangeBuffer( editor.model, editor.config.get( 'typing.undoStep' ) );
}

/**
* The current change buffer.
*
* @type {module:typing/utils/changebuffer~ChangeBuffer}
*/
get buffer() {
return this._buffer;
}

/**
* Executes the delete command. Depending on whether the selection is collapsed or not, deletes its content
* or a piece of content in the {@link #direction defined direction}.
Expand Down
3 changes: 2 additions & 1 deletion src/inputcommand.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
*/

import Command from '@ckeditor/ckeditor5-core/src/command';

import ChangeBuffer from './utils/changebuffer';

/**
Expand Down Expand Up @@ -82,7 +83,7 @@ export default class InputCommand extends Command {
this._buffer.lock();

if ( !isCollapsedRange ) {
writer.remove( range );
model.deleteContent( model.createSelection( range ) );
}

if ( text ) {
Expand Down
26 changes: 26 additions & 0 deletions tests/deletecommand.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,11 @@
* For licensing, see LICENSE.md.
*/

import VirtualTestEditor from '@ckeditor/ckeditor5-core/tests/_utils/virtualtesteditor';
import ModelTestEditor from '@ckeditor/ckeditor5-core/tests/_utils/modeltesteditor';
import DeleteCommand from '../src/deletecommand';
import Delete from '../src/delete';
import ChangeBuffer from '../src/utils/changebuffer';
import { getData, setData } from '@ckeditor/ckeditor5-engine/src/dev-utils/model';
import testUtils from '@ckeditor/ckeditor5-core/tests/_utils/utils';

Expand Down Expand Up @@ -38,6 +41,29 @@ describe( 'DeleteCommand', () => {
expect( command ).to.have.property( 'direction', 'forward' );
} );

describe( 'buffer', () => {
it( 'has buffer getter', () => {
expect( editor.commands.get( 'delete' ).buffer ).to.be.an.instanceof( ChangeBuffer );
} );

it( 'has a buffer limit configured to default value of 20', () => {
expect( editor.commands.get( 'delete' ).buffer ).to.have.property( 'limit', 20 );
} );

it( 'has a buffer configured to config.typing.undoStep', () => {
return VirtualTestEditor
.create( {
plugins: [ Delete ],
typing: {
undoStep: 5
}
} )
.then( editor => {
expect( editor.commands.get( 'delete' ).buffer ).to.have.property( 'limit', 5 );
} );
} );
} );

describe( 'execute()', () => {
it( 'uses enqueueChange', () => {
setData( model, '<paragraph>foo[]bar</paragraph>' );
Expand Down
2 changes: 1 addition & 1 deletion tests/inputcommand.js
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ describe( 'InputCommand', () => {
range: doc.selection.getFirstRange()
} );

expect( getData( model, { selection: true } ) ).to.be.equal( '<h1>Funny c[</h1><p>]ar</p>' );
expect( getData( model, { selection: true } ) ).to.be.equal( '<h1>Funny c[]ar</h1>' );
expect( buffer.size ).to.be.equal( 6 );
} );

Expand Down

0 comments on commit 5ab39fc

Please sign in to comment.