From cf16a27ac962d7bea149005f610f759bdbb948de Mon Sep 17 00:00:00 2001 From: Szymon Cofalik Date: Wed, 5 Dec 2018 16:53:36 +0100 Subject: [PATCH 1/3] Changed: Use `Model#deleteContent` helper instead of using `model.Writer` directly to remove selected content on typing. --- src/inputcommand.js | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/inputcommand.js b/src/inputcommand.js index aab7557..94ca25e 100644 --- a/src/inputcommand.js +++ b/src/inputcommand.js @@ -8,6 +8,7 @@ */ import Command from '@ckeditor/ckeditor5-core/src/command'; + import ChangeBuffer from './utils/changebuffer'; /** @@ -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 ) { From f43f7e682572c5b392035cd1ed0d88a5665355e7 Mon Sep 17 00:00:00 2001 From: Szymon Cofalik Date: Wed, 5 Dec 2018 17:08:58 +0100 Subject: [PATCH 2/3] Added: Exposed `DeleteCommand` buffer object as a readonly `buffer` property. --- src/deletecommand.js | 9 +++++++++ tests/deletecommand.js | 26 ++++++++++++++++++++++++++ 2 files changed, 35 insertions(+) diff --git a/src/deletecommand.js b/src/deletecommand.js index 9b53048..e41ed96 100644 --- a/src/deletecommand.js +++ b/src/deletecommand.js @@ -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}. diff --git a/tests/deletecommand.js b/tests/deletecommand.js index b53d6df..3c4c44c 100644 --- a/tests/deletecommand.js +++ b/tests/deletecommand.js @@ -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'; @@ -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, 'foo[]bar' ); From 4b9d6adcaffbe18da55b922f6307c659d947d0b9 Mon Sep 17 00:00:00 2001 From: Szymon Cofalik Date: Wed, 5 Dec 2018 17:09:17 +0100 Subject: [PATCH 3/3] Tests: Fixed one of `InputCommand` tests. --- tests/inputcommand.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/inputcommand.js b/tests/inputcommand.js index 44b3557..ff06953 100644 --- a/tests/inputcommand.js +++ b/tests/inputcommand.js @@ -147,7 +147,7 @@ describe( 'InputCommand', () => { range: doc.selection.getFirstRange() } ); - expect( getData( model, { selection: true } ) ).to.be.equal( '

Funny c[

]ar

' ); + expect( getData( model, { selection: true } ) ).to.be.equal( '

Funny c[]ar

' ); expect( buffer.size ).to.be.equal( 6 ); } );