浏览代码

Merge branch 'master' into ckeditor5-engine/remove-refactor

Piotrek Koszuliński 8 年之前
父节点
当前提交
0866069da0

+ 1 - 1
packages/ckeditor5-typing/src/delete.js

@@ -21,7 +21,7 @@ export default class Delete extends Plugin {
 	 * @inheritDoc
 	 */
 	static get pluginName() {
-		return 'typing/delete';
+		return 'Delete';
 	}
 
 	init() {

+ 1 - 1
packages/ckeditor5-typing/src/deletecommand.js

@@ -84,7 +84,7 @@ export default class DeleteCommand extends Command {
 				);
 			} );
 
-			dataController.deleteContent( selection, this._buffer.batch, { merge: true } );
+			dataController.deleteContent( selection, this._buffer.batch );
 			this._buffer.input( changeCount );
 
 			doc.selection.setRanges( selection.getRanges(), selection.isBackward );

+ 14 - 4
packages/ckeditor5-typing/src/input.js

@@ -26,7 +26,7 @@ export default class Input extends Plugin {
 	 * @inheritDoc
 	 */
 	static get pluginName() {
-		return 'typing/input';
+		return 'Input';
 	}
 
 	/**
@@ -42,7 +42,7 @@ export default class Input extends Plugin {
 		editor.commands.add( 'input', inputCommand );
 
 		this.listenTo( editingView, 'keydown', ( evt, data ) => {
-			this._handleKeydown( data, inputCommand.buffer );
+			this._handleKeydown( data, inputCommand );
 		}, { priority: 'lowest' } );
 
 		this.listenTo( editingView, 'mutations', ( evt, mutations, viewSelection ) => {
@@ -64,10 +64,20 @@ export default class Input extends Plugin {
 	 *
 	 * @private
 	 * @param {module:engine/view/observer/keyobserver~KeyEventData} evtData
-	 * @param {module:typing/changebuffer~ChangeBuffer} buffer
+	 * @param {module:typing/inputcommand~InputCommand} inputCommand
 	 */
-	_handleKeydown( evtData, buffer ) {
+	_handleKeydown( evtData, inputCommand ) {
 		const doc = this.editor.document;
+		const buffer = inputCommand.buffer;
+
+		// By relying on the state of the input command we allow disabling the entire input easily
+		// by just disabling the input command. We could’ve used here the delete command but that
+		// would mean requiring the delete feature which would block loading one without the other.
+		// We could also check the editor.isReadOnly property, but that wouldn't allow to block
+		// the input without blocking other features.
+		if ( !inputCommand.isEnabled ) {
+			return;
+		}
 
 		if ( isSafeKeystroke( evtData ) || doc.selection.isCollapsed ) {
 			return;

+ 1 - 1
packages/ckeditor5-typing/src/typing.js

@@ -25,6 +25,6 @@ export default class Typing extends Plugin {
 	 * @inheritDoc
 	 */
 	static get pluginName() {
-		return 'typing/typing';
+		return 'Typing';
 	}
 }

+ 30 - 1
packages/ckeditor5-typing/tests/input.js

@@ -20,7 +20,7 @@ import ViewSelection from '@ckeditor/ckeditor5-engine/src/view/selection';
 import EmitterMixin from '@ckeditor/ckeditor5-utils/src/emittermixin';
 import { getCode } from '@ckeditor/ckeditor5-utils/src/keyboard';
 
-import { getData as getModelData } from '@ckeditor/ckeditor5-engine/src/dev-utils/model';
+import { getData as getModelData, setData as setModelData } from '@ckeditor/ckeditor5-engine/src/dev-utils/model';
 import { getData as getViewData } from '@ckeditor/ckeditor5-engine/src/dev-utils/view';
 
 describe( 'Input feature', () => {
@@ -388,6 +388,15 @@ describe( 'Input feature', () => {
 
 			listenter.listenTo( view, 'keydown', () => {
 				expect( getModelData( model ) ).to.equal( '<paragraph>fo[]ar</paragraph>' );
+			}, { priority: 'lowest' } );
+		} );
+
+		// #97
+		it( 'should remove contents and merge blocks', () => {
+			setModelData( model, '<paragraph>fo[o</paragraph><paragraph>b]ar</paragraph>' );
+
+			listenter.listenTo( view, 'keydown', () => {
+				expect( getModelData( model ) ).to.equal( '<paragraph>fo[]ar</paragraph>' );
 
 				view.fire( 'mutations', [
 					{
@@ -511,6 +520,26 @@ describe( 'Input feature', () => {
 			expect( lockSpy.callCount ).to.be.equal( 0 );
 			expect( unlockSpy.callCount ).to.be.equal( 0 );
 		} );
+
+		it( 'should not modify document when input command is disabled and selection is collapsed', () => {
+			setModelData( model, '<paragraph>foo[]bar</paragraph>' );
+
+			editor.commands.get( 'input' ).isEnabled = false;
+
+			view.fire( 'keydown', { keyCode: getCode( 'b' ) } );
+
+			expect( getModelData( model ) ).to.equal( '<paragraph>foo[]bar</paragraph>' );
+		} );
+
+		it( 'should not modify document when input command is disabled and selection is non-collapsed', () => {
+			setModelData( model, '<paragraph>fo[ob]ar</paragraph>' );
+
+			editor.commands.get( 'input' ).isEnabled = false;
+
+			view.fire( 'keydown', { keyCode: getCode( 'b' ) } );
+
+			expect( getModelData( model ) ).to.equal( '<paragraph>fo[ob]ar</paragraph>' );
+		} );
 	} );
 } );