8
0
Просмотр исходного кода

Fixed: `LiveRange#event:change:content` was not fired if content was moved from the beginning of the range.

Szymon Cofalik 8 лет назад
Родитель
Сommit
46411fb0e3

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

@@ -153,7 +153,10 @@ function transform( changeType, deltaType, batch, targetRange, sourcePosition )
 	const updated = Range.createFromRanges( result );
 
 	const boundariesChanged = !updated.isEqual( this );
-	const contentChanged = updated.containsPosition( targetPosition ) || ( sourcePosition && updated.containsPosition( sourcePosition ) );
+
+	const rangeExpanded = this.containsPosition( targetPosition );
+	const rangeShrunk = sourcePosition && ( this.containsPosition( sourcePosition ) || this.start.isEqual( sourcePosition ) );
+	const contentChanged = rangeExpanded || rangeShrunk;
 
 	// If anything changed, update the range and fire an event.
 	if ( boundariesChanged || contentChanged ) {

+ 14 - 0
packages/ckeditor5-engine/tests/model/liverange.js

@@ -641,6 +641,20 @@ describe( 'LiveRange', () => {
 				expect( spy.calledOnce ).to.be.true;
 			} );
 
+			it( 'from the beginning of range', () => {
+				const moveSource = new Position( root, [ 0, 1, 4 ] );
+				const moveRange = new Range( new Position( root, [ 4, 0 ] ), new Position( root, [ 4, 3 ] ) );
+
+				const changes = {
+					range: moveRange,
+					sourcePosition: moveSource
+				};
+				doc.fire( 'change', 'move', changes, null );
+
+				expect( live.isEqual( clone ) ).to.be.true;
+				expect( spy.calledOnce ).to.be.true;
+			} );
+
 			it( 'from the range to the range', () => {
 				live.end.path = [ 0, 1, 12 ];