Sfoglia il codice sorgente

Remove old Differ.refreshItem with poc implementation.

Maciej Gołaszewski 5 anni fa
parent
commit
a081176cc8

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

@@ -168,7 +168,7 @@ export default class DowncastDispatcher {
 
 		const elementsToRefresh = new Set( found );
 
-		[ ...elementsToRefresh.values() ].forEach( element => differ._pocRefreshItem( element ) );
+		[ ...elementsToRefresh.values() ].forEach( element => differ.refreshItem( element ) );
 
 		// Before the view is updated, remove markers which have changed.
 		for ( const change of differ.getMarkersToRemove() ) {

+ 4 - 22
packages/ckeditor5-engine/src/model/differ.js

@@ -111,8 +111,10 @@ export default class Differ {
 	}
 
 	/**
-	 * Marks given `item` in differ to be "refreshed". It means that the item will be marked as removed and inserted in the differ changes
-	 * set, so it will be effectively re-converted when differ changes will be handled by a dispatcher.
+	 * Marks given `item` in differ to be "refreshed".
+	 *
+	 * It means that the item will be marked as a "refreshed" inserted in the differ changes. It will be then re-converted
+	 * when differ changes will be handled by a dispatcher.
 	 *
 	 * @param {module:engine/model/item~Item} item Item to refresh.
 	 */
@@ -121,26 +123,6 @@ export default class Differ {
 			return;
 		}
 
-		this._markRemove( item.parent, item.startOffset, item.offsetSize );
-		this._markInsert( item.parent, item.startOffset, item.offsetSize );
-
-		const range = Range._createOn( item );
-
-		for ( const marker of this._markerCollection.getMarkersIntersectingRange( range ) ) {
-			const markerRange = marker.getRange();
-
-			this.bufferMarkerChange( marker.name, markerRange, markerRange, marker.affectsData );
-		}
-
-		// Clear cache after each buffered operation as it is no longer valid.
-		this._cachedChanges = null;
-	}
-
-	_pocRefreshItem( item ) {
-		if ( this._isInInsertedElement( item.parent ) ) {
-			return;
-		}
-
 		this._markRefresh( item.parent, item.startOffset, item.offsetSize );
 
 		// @todo: Probably makes sense - check later.

+ 10 - 50
packages/ckeditor5-engine/tests/model/differ.js

@@ -1789,7 +1789,7 @@ describe( 'Differ', () => {
 		} );
 	} );
 
-	describe( '_pocRefreshItem()', () => {
+	describe( 'refreshItem()', () => {
 		beforeEach( () => {
 			root._appendChild( [
 				new Element( 'complex', null, [
@@ -1806,7 +1806,7 @@ describe( 'Differ', () => {
 		it( 'an element (block)', () => {
 			const p = root.getChild( 0 );
 
-			differ._pocRefreshItem( p );
+			differ.refreshItem( p );
 
 			expectChanges( [
 				{ type: 'refresh', name: 'paragraph', length: 1, position: model.createPositionBefore( p ) }
@@ -1816,7 +1816,7 @@ describe( 'Differ', () => {
 		it( 'an element (complex)', () => {
 			const complex = root.getChild( 2 );
 
-			differ._pocRefreshItem( complex );
+			differ.refreshItem( complex );
 
 			expectChanges( [
 				{ type: 'refresh', name: 'complex', length: 1, position: model.createPositionBefore( complex ) }
@@ -1827,7 +1827,7 @@ describe( 'Differ', () => {
 			const complex = root.getChild( 2 );
 
 			model.change( () => {
-				differ._pocRefreshItem( complex );
+				differ.refreshItem( complex );
 				remove( model.createPositionAt( complex, 1 ), 1 );
 
 				expectChanges( [
@@ -1841,7 +1841,7 @@ describe( 'Differ', () => {
 
 			model.change( () => {
 				remove( model.createPositionAt( complex, 1 ), 1 );
-				differ._pocRefreshItem( complex );
+				differ.refreshItem( complex );
 
 				expectChanges( [
 					{ type: 'refresh', name: 'complex', length: 1, position: model.createPositionBefore( complex ) },
@@ -1854,7 +1854,7 @@ describe( 'Differ', () => {
 			const complex = root.getChild( 2 );
 
 			model.change( () => {
-				differ._pocRefreshItem( complex );
+				differ.refreshItem( complex );
 				insert( new Element( 'slot' ), model.createPositionAt( complex, 2 ) );
 
 				expectChanges( [
@@ -1867,7 +1867,7 @@ describe( 'Differ', () => {
 			const complex = root.getChild( 2 );
 
 			model.change( () => {
-				differ._pocRefreshItem( complex );
+				differ.refreshItem( complex );
 				insert( new Element( 'slot' ), model.createPositionAt( complex, 2 ) );
 
 				expectChanges( [
@@ -1880,7 +1880,7 @@ describe( 'Differ', () => {
 			const complex = root.getChild( 2 );
 
 			model.change( () => {
-				differ._pocRefreshItem( complex );
+				differ.refreshItem( complex );
 				attribute( model.createRangeOn( complex ), 'foo', undefined, true );
 
 				expectChanges( [
@@ -1893,7 +1893,7 @@ describe( 'Differ', () => {
 			const complex = root.getChild( 2 );
 
 			model.change( () => {
-				differ._pocRefreshItem( complex );
+				differ.refreshItem( complex );
 				attribute( model.createRangeOn( complex ), 'foo', undefined, true );
 
 				expectChanges( [
@@ -1901,45 +1901,6 @@ describe( 'Differ', () => {
 				], true );
 			} );
 		} );
-	} );
-
-	describe( 'refreshItem()', () => {
-		it( 'should mark given element to be removed and added again', () => {
-			const p = root.getChild( 0 );
-
-			differ.refreshItem( p );
-
-			expectChanges( [
-				{ type: 'remove', name: 'paragraph', length: 1, position: model.createPositionBefore( p ) },
-				{ type: 'insert', name: 'paragraph', length: 1, position: model.createPositionBefore( p ) }
-			], true );
-		} );
-
-		it( 'should mark given text proxy to be removed and added again', () => {
-			const p = root.getChild( 0 );
-			const range = model.createRangeIn( p );
-			const textProxy = [ ...range.getItems() ][ 0 ];
-
-			differ.refreshItem( textProxy );
-
-			expectChanges( [
-				{ type: 'remove', name: '$text', length: 3, position: model.createPositionAt( p, 0 ) },
-				{ type: 'insert', name: '$text', length: 3, position: model.createPositionAt( p, 0 ) }
-			], true );
-		} );
-
-		it( 'inside a new element', () => {
-			// Since the refreshed element is inside a new element, it should not be listed on changes list.
-			model.change( () => {
-				insert( new Element( 'blockQuote', null, new Element( 'paragraph' ) ), new Position( root, [ 2 ] ) );
-
-				differ.refreshItem( root.getChild( 2 ).getChild( 0 ) );
-
-				expectChanges( [
-					{ type: 'insert', name: 'blockQuote', length: 1, position: new Position( root, [ 2 ] ) }
-				] );
-			} );
-		} );
 
 		it( 'markers refreshing', () => {
 			model.change( () => {
@@ -1961,8 +1922,7 @@ describe( 'Differ', () => {
 			differ.refreshItem( root.getChild( 1 ) );
 
 			expectChanges( [
-				{ type: 'remove', name: 'paragraph', length: 1, position: new Position( root, [ 1 ] ) },
-				{ type: 'insert', name: 'paragraph', length: 1, position: new Position( root, [ 1 ] ) }
+				{ type: 'refresh', name: 'paragraph', length: 1, position: new Position( root, [ 1 ] ) }
 			] );
 
 			const markersToRemove = differ.getMarkersToRemove().map( entry => entry.name );

+ 1 - 1
packages/ckeditor5-table/src/converters/table-cell-refresh-post-fixer.js

@@ -96,7 +96,7 @@ function tableCellRefreshPostFixer( model ) {
 		for ( const tableCell of cellsToRefresh.values() ) {
 			for ( const paragraph of [ ...tableCell.getChildren() ].filter( child => child.is( 'element', 'paragraph' ) ) ) {
 				// @if CK_DEBUG_TABLE // console.log( `Post-fixing table: refreshing paragraph in table cell (${++paragraphsRefreshed}).` );
-				differ._pocRefreshItem( paragraph );
+				differ.refreshItem( paragraph );
 			}
 		}