Explorar el Código

Renamed event. Switched listening method to listenTo.

Maciej Bukowski hace 8 años
padre
commit
6e2172a57c

+ 4 - 4
packages/ckeditor5-clipboard/src/clipboard.js

@@ -32,7 +32,7 @@ import HtmlDataProcessor from '@ckeditor/ckeditor5-engine/src/dataprocessor/html
  *
  * 1. get HTML or plain text from the clipboard,
  * 2. prevent the default action of the native `paste` or `drop` event,
- * 3. fire {@link module:engine/view/document~Document#event:input} with a
+ * 3. fire {@link module:engine/view/document~Document#event:clipboardInput} with a
  * {@link module:clipboard/datatransfer~DataTransfer `dataTransfer`} property.
  * 4. fire {@link module:clipboard/clipboard~Clipboard#event:inputTransformation} with a `data` containing the clipboard data parsed to
  * a {@link module:engine/view/documentfragment~DocumentFragment view document fragment}.
@@ -42,13 +42,13 @@ import HtmlDataProcessor from '@ckeditor/ckeditor5-engine/src/dataprocessor/html
  * data from the clipboard (the {@link module:clipboard/datatransfer~DataTransfer `DataTransfer`}).
  * should plug a listener at this stage.
  *
- * ### On {@link module:engine/view/document~Document#event:input}
+ * ### On {@link module:engine/view/document~Document#event:clipboardInput}
  *
  * This action is performed by a low priority listener, so it can be overridden by a normal one.
  *
  * At this stage the dataTransfer object can be processed by the features, which want to transform the original dataTransform.
  *
- *		this.listenTo( editor.editing.view, 'input', ( evt, data ) => {
+ *		this.listenTo( editor.editing.view, 'clipboardInput', ( evt, data ) => {
  *			const content = customTransform( data.dataTransfer.get( 'text/html' ) );
  *			const transformedContent = transform( content );
  * 			data.dataTransfer.set( 'text/html', transformedContent );
@@ -132,7 +132,7 @@ export default class Clipboard extends Plugin {
 
 		// The clipboard paste pipeline.
 
-		this.listenTo( editingView, 'input', ( evt, data ) => {
+		this.listenTo( editingView, 'clipboardInput', ( evt, data ) => {
 			const dataTransfer = data.dataTransfer;
 			let content = '';
 

+ 4 - 5
packages/ckeditor5-clipboard/src/clipboardobserver.js

@@ -24,14 +24,13 @@ export default class ClipboardObserver extends DomEventObserver {
 
 		this.domEventType = [ 'paste', 'copy', 'cut', 'drop' ];
 
-		doc.on( 'paste', _handleInput, { priority: 'low' } );
-		doc.on( 'drop', _handleInput, { priority: 'low' } );
+		this.listenTo( doc, 'paste', handleInput, { priority: 'low' } );
+		this.listenTo( doc, 'drop', handleInput, { priority: 'low' } );
 
-		function _handleInput( evt, data ) {
-			// Prevent page refreshing.
+		function handleInput( evt, data ) {
 			data.preventDefault();
 
-			doc.fire( 'input', { dataTransfer: data.dataTransfer } );
+			doc.fire( 'clipboardInput', { dataTransfer: data.dataTransfer } );
 		}
 	}
 

+ 9 - 9
packages/ckeditor5-clipboard/tests/clipboard.js

@@ -41,11 +41,11 @@ describe( 'Clipboard feature', () => {
 
 	describe( 'clipboard paste pipeline', () => {
 		describe( 'takes HTML data from the dataTransfer', () => {
-			it( 'and fires the input event on the editingView', ( done ) => {
+			it( 'and fires the clipboardInput event on the editingView', ( done ) => {
 				const dataTransferMock = createDataTransfer( { 'text/html': '<p>x</p>', 'text/plain': 'y' } );
 				const preventDefaultSpy = sinon.spy();
 
-				editingView.on( 'input', ( evt, data ) => {
+				editingView.on( 'clipboardInput', ( evt, data ) => {
 					expect( preventDefaultSpy.calledOnce ).to.be.true;
 					expect( data.dataTransfer ).to.equal( dataTransferMock );
 
@@ -77,11 +77,11 @@ describe( 'Clipboard feature', () => {
 		} );
 
 		describe( 'takes plain text data from the dataTransfer if there is no HTML', () => {
-			it( 'and fires the input event on the editingView', ( done ) => {
+			it( 'and fires the clipboardInput event on the editingView', ( done ) => {
 				const dataTransferMock = createDataTransfer( { 'text/plain': 'x\n\ny  z' } );
 				const preventDefaultSpy = sinon.spy();
 
-				editingView.on( 'input', ( evt, data ) => {
+				editingView.on( 'clipboardInput', ( evt, data ) => {
 					expect( preventDefaultSpy.calledOnce ).to.be.true;
 					expect( data.dataTransfer ).to.equal( dataTransferMock );
 
@@ -117,7 +117,7 @@ describe( 'Clipboard feature', () => {
 			const preventDefaultSpy = sinon.spy();
 			const editorViewCalled = sinon.spy();
 
-			editingView.on( 'input', ( evt, data ) => {
+			editingView.on( 'clipboardInput', ( evt, data ) => {
 				expect( preventDefaultSpy.calledOnce ).to.be.true;
 
 				expect( data.dataTransfer ).to.equal( dataTransferMock );
@@ -148,7 +148,7 @@ describe( 'Clipboard feature', () => {
 				evt.stop();
 			} );
 
-			editingView.on( 'input', spy );
+			editingView.on( 'clipboardInput', spy );
 
 			editingView.fire( 'paste', {
 				dataTransfer: dataTransferMock,
@@ -190,7 +190,7 @@ describe( 'Clipboard feature', () => {
 			const dataTransferMock = createDataTransfer( { 'text/plain': '' } );
 			const spy = sinon.stub( editor.data, 'insertContent' );
 
-			editingView.fire( 'input', {
+			editingView.fire( 'clipboardInput', {
 				dataTransfer: dataTransferMock,
 				content: new ViewDocumentFragment()
 			} );
@@ -198,11 +198,11 @@ describe( 'Clipboard feature', () => {
 			expect( spy.callCount ).to.equal( 0 );
 		} );
 
-		it( 'uses low priority observer for the input event', () => {
+		it( 'uses low priority observer for the clipboardInput event', () => {
 			const dataTransferMock = createDataTransfer( { 'text/html': 'x' } );
 			const spy = sinon.stub( editor.data, 'insertContent' );
 
-			editingView.on( 'input', ( evt ) => {
+			editingView.on( 'clipboardInput', ( evt ) => {
 				evt.stop();
 			} );