Explorar o código

Change: Make second parameter of `LiveRange#event:change` an object.

Szymon Cofalik %!s(int64=7) %!d(string=hai) anos
pai
achega
acfb0bda47

+ 2 - 2
packages/ckeditor5-engine/src/model/documentselection.js

@@ -750,14 +750,14 @@ class LiveSelection extends Selection {
 
 		const liveRange = LiveRange.createFromRange( range );
 
-		liveRange.on( 'change:range', ( evt, oldRange, deletionPosition ) => {
+		liveRange.on( 'change:range', ( evt, oldRange, data ) => {
 			this._hasChangedRange = true;
 
 			// If `LiveRange` is in whole moved to the graveyard, save necessary data. It will be fixed on `Model#applyOperation` event.
 			if ( liveRange.root == this._document.graveyard ) {
 				this._fixGraveyardRangesData.push( {
 					liveRange,
-					sourcePosition: deletionPosition
+					sourcePosition: data.deletionPosition
 				} );
 			}
 		} );

+ 3 - 4
packages/ckeditor5-engine/src/model/liverange.js

@@ -143,10 +143,9 @@ function transform( operation ) {
 	const result = Range.createFromRanges( ranges );
 	const boundariesChanged = !result.isEqual( this );
 	const contentChanged = doesOperationChangeRangeContent( this, operation );
+	let deletionPosition = null;
 
 	if ( boundariesChanged ) {
-		let deletionPosition = null;
-
 		if ( result.root.rootName == '$graveyard' ) {
 			if ( operation.type == 'remove' ) {
 				deletionPosition = operation.sourcePosition;
@@ -162,10 +161,10 @@ function transform( operation ) {
 		this.start = result.start;
 		this.end = result.end;
 
-		this.fire( 'change:range', oldRange, deletionPosition );
+		this.fire( 'change:range', oldRange, { deletionPosition } );
 	} else if ( contentChanged ) {
 		// If range boundaries have not changed, but there was change inside the range, fire `change:content` event.
-		this.fire( 'change:content', Range.createFromRange( this ), null );
+		this.fire( 'change:content', Range.createFromRange( this ), { deletionPosition } );
 	}
 }
 

+ 4 - 4
packages/ckeditor5-engine/tests/model/liverange.js

@@ -113,7 +113,7 @@ describe( 'LiveRange', () => {
 		expect( spy.args[ 0 ][ 1 ].isEqual( copy ) ).to.be.true;
 
 		// Second parameter is null for operations that did not move the range into graveyard.
-		expect( spy.args[ 0 ][ 2 ] ).to.be.null;
+		expect( spy.args[ 0 ][ 2 ].deletionPosition ).to.be.null;
 	} );
 
 	it( 'should fire change:content event when content inside the range has changed', () => {
@@ -137,7 +137,7 @@ describe( 'LiveRange', () => {
 		expect( spy.args[ 0 ][ 1 ].isEqual( live ) ).to.be.true;
 
 		// Second parameter is null for operations that did not move the range into graveyard.
-		expect( spy.args[ 0 ][ 2 ] ).to.be.null;
+		expect( spy.args[ 0 ][ 2 ].deletionPosition ).to.be.null;
 	} );
 
 	it( 'should pass deletion position if range was removed (remove)', () => {
@@ -153,7 +153,7 @@ describe( 'LiveRange', () => {
 		} );
 
 		// Second parameter is deletion position.
-		expect( spy.args[ 0 ][ 2 ].isEqual( sourcePosition ) ).to.be.true;
+		expect( spy.args[ 0 ][ 2 ].deletionPosition.isEqual( sourcePosition ) ).to.be.true;
 	} );
 
 	// This scenario is hypothetically possible during OT if the element to merge-into was removed.
@@ -191,7 +191,7 @@ describe( 'LiveRange', () => {
 		} );
 
 		// Second parameter is deletion position.
-		expect( spy.args[ 1 ][ 2 ].isEqual( new Position( root, [ 0 ] ) ) ).to.be.true;
+		expect( spy.args[ 1 ][ 2 ].deletionPosition.isEqual( new Position( root, [ 0 ] ) ) ).to.be.true;
 	} );
 
 	describe( 'should get transformed and fire change:range if', () => {