浏览代码

Merge branch 'master' into t/ckeditor5-engine/1556

Piotr Jasiun 7 年之前
父节点
当前提交
d3ed77a66d

+ 9 - 0
packages/ckeditor5-typing/src/deletecommand.js

@@ -49,6 +49,15 @@ export default class DeleteCommand extends Command {
 	}
 
 	/**
+	 * 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}.
 	 *

+ 2 - 1
packages/ckeditor5-typing/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 ) {

+ 26 - 0
packages/ckeditor5-typing/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, '<paragraph>foo[]bar</paragraph>' );

+ 1 - 1
packages/ckeditor5-typing/tests/inputcommand.js

@@ -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 );
 		} );