Selaa lähdekoodia

Merge pull request #552 from ckeditor/t/551

Fixed: fixes required by changes in utils.EmitterMixin
Piotr Jasiun 9 vuotta sitten
vanhempi
commit
d0dd80b828

+ 9 - 9
packages/ckeditor5-engine/src/conversion/buildmodelconverter.js

@@ -186,23 +186,23 @@ class ModelConverterBuilder {
 	 * @param {String|engine.view.ViewElement|Function} element Element created by converter.
 	 */
 	toElement( element ) {
-		const priority = this._from.priority === null ? 10 : this._from.priority;
+		const priority = this._from.priority === null ? 'normal' : this._from.priority;
 
 		for ( let dispatcher of this._dispatchers ) {
 			if ( this._from.type == 'element' ) {
 				// From model element to view element -> insert element.
 				element = typeof element == 'string' ? new ViewContainerElement( element ) : element;
 
-				dispatcher.on( 'insert:' + this._from.name, insertElement( element ), null, priority );
+				dispatcher.on( 'insert:' + this._from.name, insertElement( element ), priority );
 			} else {
 				// From model attribute to view element -> wrap and unwrap.
 				element = typeof element == 'string' ? new ViewAttributeElement( element ) : element;
 
-				dispatcher.on( 'addAttribute:' + this._from.key, wrap( element ), null, priority );
-				dispatcher.on( 'changeAttribute:' + this._from.key, wrap( element ), null, priority );
-				dispatcher.on( 'removeAttribute:' + this._from.key, unwrap( element ), null, priority );
+				dispatcher.on( 'addAttribute:' + this._from.key, wrap( element ), priority );
+				dispatcher.on( 'changeAttribute:' + this._from.key, wrap( element ), priority );
+				dispatcher.on( 'removeAttribute:' + this._from.key, unwrap( element ), priority );
 
-				dispatcher.on( 'selectionAttribute:' + this._from.key, convertSelectionAttribute( element ), null, priority );
+				dispatcher.on( 'selectionAttribute:' + this._from.key, convertSelectionAttribute( element ), priority );
 			}
 		}
 	}
@@ -268,9 +268,9 @@ class ModelConverterBuilder {
 		}
 
 		for ( let dispatcher of this._dispatchers ) {
-			dispatcher.on( 'addAttribute:' + this._from.key, setAttribute( attributeCreator ), null, this._from.priority || 10 );
-			dispatcher.on( 'changeAttribute:' + this._from.key, setAttribute( attributeCreator ), null, this._from.priority || 10 );
-			dispatcher.on( 'removeAttribute:' + this._from.key, removeAttribute( attributeCreator ), null, this._from.priority || 10 );
+			dispatcher.on( 'addAttribute:' + this._from.key, setAttribute( attributeCreator ), this._from.priority || 'normal' );
+			dispatcher.on( 'changeAttribute:' + this._from.key, setAttribute( attributeCreator ), this._from.priority || 'normal' );
+			dispatcher.on( 'removeAttribute:' + this._from.key, removeAttribute( attributeCreator ), this._from.priority || 'normal' );
 		}
 	}
 }

+ 3 - 3
packages/ckeditor5-engine/src/conversion/buildviewconverter.js

@@ -297,7 +297,7 @@ class ViewConverterBuilder {
 			};
 		};
 
-		this._setCallback( eventCallbackGen, 10 );
+		this._setCallback( eventCallbackGen, 'normal' );
 	}
 
 	/**
@@ -352,7 +352,7 @@ class ViewConverterBuilder {
 			};
 		};
 
-		this._setCallback( eventCallbackGen, 1000 );
+		this._setCallback( eventCallbackGen, 'low' );
 	}
 
 	/**
@@ -375,7 +375,7 @@ class ViewConverterBuilder {
 
 			// Add event to each registered dispatcher.
 			for ( let dispatcher of this._dispatchers ) {
-				dispatcher.on( eventName, eventCallback, null, priority );
+				dispatcher.on( eventName, eventCallback, priority );
 			}
 		}
 	}

+ 1 - 1
packages/ckeditor5-engine/src/conversion/modelconversiondispatcher.js

@@ -97,7 +97,7 @@ import extend from '../../utils/lib/lodash/extend.js';
  *			viewWriter.insert( position, viewSourceBtn );
  *
  *			evt.stop();
- *		}, 1 );
+ *		}, 'high' );
  *
  * @memberOf engine.conversion
  */

+ 4 - 4
packages/ckeditor5-engine/src/datacontroller.js

@@ -78,7 +78,7 @@ export default class DataController {
 		this.modelToView = new ModelConversionDispatcher( {
 			mapper: this._mapper
 		} );
-		this.modelToView.on( 'insert:$text', insertText() );
+		this.modelToView.on( 'insert:$text', insertText(), 'lowest' );
 
 		/**
 		 * View to model conversion dispatcher used by the {@link engine.DataController#set set method}.
@@ -102,9 +102,9 @@ export default class DataController {
 		// Note that if there is no default converter for the element it will be skipped, for instance `<b>foo</b>` will be
 		// converted to nothing. We add `convertToModelFragment` as a last converter so it converts children of that
 		// element to the document fragment so `<b>foo</b>` will be converted to `foo` if there is no converter for `<b>`.
-		this.viewToModel.on( 'text', convertText() );
-		this.viewToModel.on( 'element', convertToModelFragment(), null, 9999 );
-		this.viewToModel.on( 'documentFragment', convertToModelFragment(), null, 9999 );
+		this.viewToModel.on( 'text', convertText(), 'lowest' );
+		this.viewToModel.on( 'element', convertToModelFragment(), 'lowest' );
+		this.viewToModel.on( 'documentFragment', convertToModelFragment(), 'lowest' );
 	}
 
 	/**

+ 13 - 11
packages/ckeditor5-engine/src/editingcontroller.js

@@ -83,27 +83,29 @@ export default class EditingController {
 		 */
 		this._listenter = Object.create( EmitterMixin );
 
-		// Convert view selection to model.
-		this._listenter.listenTo( this.view, 'selectionChange', convertSelectionChange( model, this.mapper ) );
-
+		// Convert changes in model to view.
 		this._listenter.listenTo( this.model, 'change', ( evt, type, changes ) => {
 			this.modelToView.convertChange( type, changes );
-		} );
+		}, 'low' );
 
+		// Convert model selection to view.
 		this._listenter.listenTo( this.model, 'changesDone', () => {
 			this.modelToView.convertSelection( model.selection );
 			this.view.render();
-		} );
+		}, 'low' );
+
+		// Convert view selection to model.
+		this._listenter.listenTo( this.view, 'selectionChange', convertSelectionChange( model, this.mapper ) );
 
 		// Attach default content converters.
-		this.modelToView.on( 'insert:$text', insertText() );
-		this.modelToView.on( 'remove', remove() );
-		this.modelToView.on( 'move', move() );
+		this.modelToView.on( 'insert:$text', insertText(), 'lowest' );
+		this.modelToView.on( 'remove', remove(), 'low' );
+		this.modelToView.on( 'move', move(), 'low' );
 
 		// Attach default selection converters.
-		this.modelToView.on( 'selection', clearAttributes() );
-		this.modelToView.on( 'selection', convertRangeSelection() );
-		this.modelToView.on( 'selection', convertCollapsedSelection() );
+		this.modelToView.on( 'selection', clearAttributes(), 'low' );
+		this.modelToView.on( 'selection', convertRangeSelection(), 'low' );
+		this.modelToView.on( 'selection', convertCollapsedSelection(), 'low' );
 	}
 
 	/**

+ 1 - 2
packages/ckeditor5-engine/src/model/liveposition.js

@@ -129,8 +129,7 @@ function bindWithDocument() {
 		'change',
 		( event, type, changes ) => {
 			transform.call( this, type, changes.range, changes.sourcePosition );
-		},
-		this
+		}
 	);
 }
 

+ 1 - 2
packages/ckeditor5-engine/src/model/liverange.js

@@ -89,8 +89,7 @@ function bindWithDocument() {
 		'change',
 		( event, type, changes ) => {
 			transform.call( this, type, changes.range, changes.sourcePosition );
-		},
-		this
+		}
 	);
 }
 

+ 1 - 1
packages/ckeditor5-engine/src/view/editableelement.js

@@ -58,7 +58,7 @@ export default class EditableElement extends ContainerElement {
 		// but this does not mean that editable has focus - it will be placed there after rendering.
 		this.listenTo( document, 'render', () => {
 			this.isFocused = document.isFocused && document.selection.editableElement == this;
-		}, null, 11 );
+		}, 'low' );
 	}
 
 	/**

+ 17 - 25
packages/ckeditor5-engine/tests/conversion/advanced-converters.js

@@ -332,8 +332,8 @@ describe( 'image with caption converters', () => {
 describe( 'custom attribute handling for given element', () => {
 	beforeEach( () => {
 		// NORMAL LINK MODEL TO VIEW CONVERTERS
-		modelDispatcher.on( 'addAttribute:linkHref', wrap( ( value ) => new ViewAttributeElement( 'a', { href: value } ) ), null, 99 );
-		modelDispatcher.on( 'addAttribute:linkTitle', wrap( ( value ) => new ViewAttributeElement( 'a', { title: value } ) ), null, 99 );
+		modelDispatcher.on( 'addAttribute:linkHref', wrap( ( value ) => new ViewAttributeElement( 'a', { href: value } ) ) );
+		modelDispatcher.on( 'addAttribute:linkTitle', wrap( ( value ) => new ViewAttributeElement( 'a', { title: value } ) ) );
 
 		const changeLinkAttribute = function( elementCreator ) {
 			return ( evt, data, consumable, conversionApi ) => {
@@ -352,30 +352,22 @@ describe( 'custom attribute handling for given element', () => {
 
 		modelDispatcher.on(
 			'changeAttribute:linkHref',
-			changeLinkAttribute( ( value ) => new ViewAttributeElement( 'a', { href: value } ) ),
-			null,
-			99
+			changeLinkAttribute( ( value ) => new ViewAttributeElement( 'a', { href: value } ) )
 		);
 
 		modelDispatcher.on(
 			'changeAttribute:linkTitle',
-			changeLinkAttribute( ( value ) => new ViewAttributeElement( 'a', { title: value } ) ),
-			null,
-			99
+			changeLinkAttribute( ( value ) => new ViewAttributeElement( 'a', { title: value } ) )
 		);
 
 		modelDispatcher.on(
 			'removeAttribute:linkHref',
-			unwrap( ( value ) => new ViewAttributeElement( 'a', { href: value } ) ),
-			null,
-			99
+			unwrap( ( value ) => new ViewAttributeElement( 'a', { href: value } ) )
 		);
 
 		modelDispatcher.on(
 			'removeAttribute:linkTitle',
-			unwrap( ( value ) => new ViewAttributeElement( 'a', { title: value } ) ),
-			null,
-			99
+			unwrap( ( value ) => new ViewAttributeElement( 'a', { title: value } ) )
 		);
 
 		// NORMAL LINK VIEW TO MODEL CONVERTERS
@@ -424,7 +416,7 @@ describe( 'custom attribute handling for given element', () => {
 			}
 
 			evt.stop();
-		} );
+		}, 'high' );
 
 		const modelChangeLinkAttrQuoteConverter = function( evt, data, consumable, conversionApi ) {
 			let viewKey = data.attributeKey.substr( 4 ).toLowerCase();
@@ -443,8 +435,8 @@ describe( 'custom attribute handling for given element', () => {
 			evt.stop();
 		};
 
-		modelDispatcher.on( 'changeAttribute:linkHref:quote', modelChangeLinkAttrQuoteConverter );
-		modelDispatcher.on( 'changeAttribute:linkTitle:quote', modelChangeLinkAttrQuoteConverter );
+		modelDispatcher.on( 'changeAttribute:linkHref:quote', modelChangeLinkAttrQuoteConverter, 'high' );
+		modelDispatcher.on( 'changeAttribute:linkTitle:quote', modelChangeLinkAttrQuoteConverter, 'high' );
 
 		modelDispatcher.on( 'removeAttribute:linkHref:quote', ( evt, data, consumable, conversionApi ) => {
 			consumable.consume( data.item, eventNameToConsumableType( evt.name ) );
@@ -456,8 +448,8 @@ describe( 'custom attribute handling for given element', () => {
 			viewWriter.remove( ViewRange.createFromParentsAndOffsets( viewElement, aIndex, viewElement, aIndex + 1 ) );
 
 			evt.stop();
-		} );
-		modelDispatcher.on( 'removeAttribute:linkTitle:quote', modelChangeLinkAttrQuoteConverter );
+		}, 'high' );
+		modelDispatcher.on( 'removeAttribute:linkTitle:quote', modelChangeLinkAttrQuoteConverter, 'high' );
 
 		// QUOTE VIEW TO MODEL CONVERTERS
 		viewDispatcher.on( 'element:blockquote', ( evt, data, consumable, conversionApi ) => {
@@ -660,10 +652,10 @@ it( 'default table view to model converter', () => {
 describe( 'universal converter', () => {
 	beforeEach( () => {
 		// "Universal" converters
-		modelDispatcher.on( 'insert', insertElement( ( data ) => new ViewContainerElement( data.item.name ) ), null, 99 );
-		modelDispatcher.on( 'addAttribute', setAttribute(), null, 99 );
-		modelDispatcher.on( 'changeAttribute', setAttribute(), null, 99 );
-		modelDispatcher.on( 'removeAttribute', removeAttribute(), null, 99 );
+		modelDispatcher.on( 'insert', insertElement( ( data ) => new ViewContainerElement( data.item.name ) ), 'lowest' );
+		modelDispatcher.on( 'addAttribute', setAttribute(), 'lowest' );
+		modelDispatcher.on( 'changeAttribute', setAttribute(), 'lowest' );
+		modelDispatcher.on( 'removeAttribute', removeAttribute(), 'lowest' );
 
 		viewDispatcher.on( 'element', ( evt, data, consumable, conversionApi ) => {
 			if ( consumable.consume( data.input, { name: true } ) ) {
@@ -677,9 +669,9 @@ describe( 'universal converter', () => {
 
 				data.output.appendChildren( conversionApi.convertChildren( data.input, consumable ) );
 			}
-		}, null, 99 );
+		}, 'lowest' );
 
-		// "Real" converters -- added with sooner priority. Should overwrite the "universal" converters.
+		// "Real" converters -- added with higher priority. Should overwrite the "universal" converters.
 		modelDispatcher.on( 'insert:image', insertElement( new ViewContainerElement( 'img' ) ) );
 		modelDispatcher.on( 'addAttribute:bold', wrap( new ViewAttributeElement( 'strong' ) ) );
 		modelDispatcher.on( 'changeAttribute:bold', wrap( new ViewAttributeElement( 'strong' ) ) );

+ 1 - 1
packages/ckeditor5-engine/tests/conversion/buildmodelconverter.js

@@ -343,7 +343,7 @@ describe( 'Model converter builder', () => {
 	describe( 'withPriority', () => {
 		it( 'should change default converters priority', () => {
 			buildModelConverter().for( dispatcher ).fromElement( 'custom' ).toElement( 'custom' );
-			buildModelConverter().for( dispatcher ).fromElement( 'custom' ).withPriority( 0 ).toElement( 'other' );
+			buildModelConverter().for( dispatcher ).fromElement( 'custom' ).withPriority( 'high' ).toElement( 'other' );
 
 			let modelElement = new ModelElement( 'custom', null, new ModelText( 'foobar' ) );
 			modelRoot.appendChildren( modelElement );

+ 1 - 1
packages/ckeditor5-engine/tests/conversion/buildviewconverter.js

@@ -287,7 +287,7 @@ describe( 'View converter builder', () => {
 		expect( modelToString( result ) ).to.equal( '<paragraph class="myClass">foo</paragraph>' );
 
 		buildViewConverter().for( dispatcher )
-			.from( { name: 'p', class: 'myClass' } ).withPriority( -1 ) // Default for `toElement` is 0.
+			.from( { name: 'p', class: 'myClass' } ).withPriority( 'high' )
 			.toElement( 'customP' );
 
 		result = dispatcher.convert( new ViewContainerElement( 'p', { class: 'myClass' }, new ViewText( 'foo' ) ), objWithContext );

+ 8 - 8
packages/ckeditor5-engine/tests/conversion/model-selection-to-view-converters.js

@@ -55,9 +55,9 @@ beforeEach( () => {
 	dispatcher.on( 'addAttribute:bold', wrap( new ViewAttributeElement( 'strong' ) ) );
 
 	// Default selection converters.
-	dispatcher.on( 'selection', clearAttributes() );
-	dispatcher.on( 'selection', convertRangeSelection() );
-	dispatcher.on( 'selection', convertCollapsedSelection() );
+	dispatcher.on( 'selection', clearAttributes(), 'low' );
+	dispatcher.on( 'selection', convertRangeSelection(), 'low' );
+	dispatcher.on( 'selection', convertCollapsedSelection(), 'low' );
 } );
 
 describe( 'default converters', () => {
@@ -145,7 +145,7 @@ describe( 'default converters', () => {
 			// This should prevent default callback doing anything.
 			dispatcher.on( 'selection', ( evt, data, consumable ) => {
 				expect( consumable.consume( data.selection, 'selection' ) ).to.be.true;
-			}, null, 0 );
+			}, 'high' );
 
 			// Similar test case as the first in this suite.
 			test(
@@ -206,11 +206,11 @@ describe( 'default converters', () => {
 			// This should prevent default callbacks doing anything.
 			dispatcher.on( 'selection', ( evt, data, consumable ) => {
 				expect( consumable.consume( data.selection, 'selection' ) ).to.be.true;
-			}, null, 0 );
+			}, 'high' );
 
 			dispatcher.on( 'selectionAttribute:bold', ( evt, data, consumable ) => {
 				expect( consumable.consume( data.selection, 'selectionAttribute:bold' ) ).to.be.true;
-			}, null, 0 );
+			}, 'high' );
 
 			// Similar test case as above
 			test(
@@ -431,7 +431,7 @@ describe( 'table cell selection converter', () => {
 					viewNode.addClass( 'selected' );
 				}
 			}
-		}, null, 0 );
+		} );
 	} );
 
 	it( 'should not be used to convert selection that is not on table cell', () => {
@@ -445,7 +445,7 @@ describe( 'table cell selection converter', () => {
 	it( 'should add a class to the selected table cell', () => {
 		modelDoc.schema.registerItem( 'table', '$block' );
 		test(
-			// table tr#0, table tr#1
+			// table tr#0 |td#0, table tr#0 td#0|
 			[ [ 0, 0, 0 ], [ 0, 0, 1 ] ],
 			'<table><tr><td>foo</td></tr><tr><td>bar</td></tr></table>',
 			'<table><tr><td class="selected">foo</td></tr><tr><td>bar</td></tr></table>'

+ 6 - 6
packages/ckeditor5-engine/tests/conversion/view-to-model-converters.js

@@ -42,9 +42,9 @@ describe( 'convertText', () => {
 	it( 'should not convert already consumed texts', () => {
 		const viewText = new ViewText( 'foofuckbafuckr' );
 
-		// Default converter for elements. Returns just converted children. Added with late priority.
-		dispatcher.on( 'text', convertText(), dispatcher, 9999 );
-		// Added with sooner priority. Should make the above converter not fire.
+		// Default converter for elements. Returns just converted children. Added with lowest priority.
+		dispatcher.on( 'text', convertText(), 'lowest' );
+		// Added with normal priority. Should make the above converter not fire.
 		dispatcher.on( 'text', ( evt, data, consumable ) => {
 			if ( consumable.consume( data.input ) ) {
 				data.output = new ModelText( data.input.data.replace( /fuck/gi, '****' ) );
@@ -109,9 +109,9 @@ describe( 'convertToModelFragment', () => {
 
 		// To get any meaningful results we have to actually convert something.
 		dispatcher.on( 'text', convertText() );
-		// Default converter for elements. Returns just converted children. Added with late priority.
-		dispatcher.on( 'element', convertToModelFragment(), dispatcher, 9999 );
-		// Added with sooner priority. Should make the above converter not fire.
+		// Default converter for elements. Returns just converted children. Added with lowest priority.
+		dispatcher.on( 'element', convertToModelFragment(), 'lowest' );
+		// Added with normal priority. Should make the above converter not fire.
 		dispatcher.on( 'element:p', ( evt, data, consumable, conversionApi ) => {
 			if ( consumable.consume( data.input, { name: true } ) ) {
 				data.output = new ModelElement( 'paragraph' );