Przeglądaj źródła

Added: Exposed `DeleteCommand` buffer object as a readonly `buffer` property.

Szymon Cofalik 7 lat temu
rodzic
commit
0aabde991b

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

@@ -48,6 +48,15 @@ export default class DeleteCommand extends Command {
 		this._buffer = new ChangeBuffer( editor.model, editor.config.get( 'typing.undoStep' ) );
 		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
 	 * 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}.
 	 * or a piece of content in the {@link #direction defined direction}.

+ 26 - 0
packages/ckeditor5-typing/tests/deletecommand.js

@@ -3,8 +3,11 @@
  * For licensing, see LICENSE.md.
  * For licensing, see LICENSE.md.
  */
  */
 
 
+import VirtualTestEditor from '@ckeditor/ckeditor5-core/tests/_utils/virtualtesteditor';
 import ModelTestEditor from '@ckeditor/ckeditor5-core/tests/_utils/modeltesteditor';
 import ModelTestEditor from '@ckeditor/ckeditor5-core/tests/_utils/modeltesteditor';
 import DeleteCommand from '../src/deletecommand';
 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 { getData, setData } from '@ckeditor/ckeditor5-engine/src/dev-utils/model';
 import testUtils from '@ckeditor/ckeditor5-core/tests/_utils/utils';
 import testUtils from '@ckeditor/ckeditor5-core/tests/_utils/utils';
 
 
@@ -38,6 +41,29 @@ describe( 'DeleteCommand', () => {
 		expect( command ).to.have.property( 'direction', 'forward' );
 		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()', () => {
 	describe( 'execute()', () => {
 		it( 'uses enqueueChange', () => {
 		it( 'uses enqueueChange', () => {
 			setData( model, '<paragraph>foo[]bar</paragraph>' );
 			setData( model, '<paragraph>foo[]bar</paragraph>' );