8
0
فهرست منبع

Renamed insert to insertContent and changed it param to model's doc frag.

Piotrek Koszuliński 9 سال پیش
والد
کامیت
978a211a99

+ 7 - 7
packages/ckeditor5-engine/src/controller/datacontroller.js

@@ -19,7 +19,7 @@ import ViewDocumentFragment from '../view/documentfragment.js';
 import ModelRange from '../model/range.js';
 import ModelPosition from '../model/position.js';
 
-import insert from './insert.js';
+import insertContent from './insertcontent.js';
 
 /**
  * Controller for the data pipeline. The data pipeline controls how data is retrieved from the document
@@ -111,7 +111,7 @@ export default class DataController {
 		this.viewToModel.on( 'element', convertToModelFragment(), { priority: 'lowest' } );
 		this.viewToModel.on( 'documentFragment', convertToModelFragment(), { priority: 'lowest' } );
 
-		this.on( 'insert', ( evt, data ) => insert( this, data.content, data.selection, data.batch ) );
+		this.on( 'insertContent', ( evt, data ) => insertContent( this, data.content, data.selection, data.batch ) );
 	}
 
 	/**
@@ -214,16 +214,16 @@ export default class DataController {
 	destroy() {}
 
 	/**
-	 * See {@link engine.controller.insert}.
+	 * See {@link engine.controller.insertContent}.
 	 *
-	 * @fires engine.controller.DataController#insert
-	 * @param {engine.view.DocumentFragment} content The content to insert.
+	 * @fires engine.controller.DataController#insertContent
+	 * @param {engine.model.DocumentFragment} content The content to insert.
 	 * @param {engine.model.Selection} selection Selection into which the content should be inserted.
 	 * @param {engine.model.Batch} [batch] Batch to which deltas will be added. If not specified, then
 	 * changes will be added to a new batch.
 	 */
-	insert( content, selection, batch ) {
-		this.fire( 'insert', { content, selection, batch } );
+	insertContent( content, selection, batch ) {
+		this.fire( 'insertContent', { content, selection, batch } );
 	}
 }
 

+ 18 - 19
packages/ckeditor5-engine/src/controller/insert.js → packages/ckeditor5-engine/src/controller/insertcontent.js

@@ -10,25 +10,23 @@ import Element from '../model/element.js';
 import Range from '../model/range.js';
 import log from '../../utils/log.js';
 
-// import { stringify as stringifyModel } from '../dev-utils/model.js';
-
 /**
  * Inserts content into the editor (specified selection) as one would expect the paste
  * functionality to work.
  *
- * **Note:** Use {@link engine.controller.DataController#insert} instead of this function.
- * This function is only exposed to be reusable in algorithms which change the {@link engine.controller.DataController#insert}
+ * **Note:** Use {@link engine.controller.DataController#insertContent} instead of this function.
+ * This function is only exposed to be reusable in algorithms which change the {@link engine.controller.DataController#insertContent}
  * method's behavior.
  *
- * @method engine.controller.insert
+ * @method engine.controller.insertContent
  * @param {engine.controller.DataController} dataController The data controller in context of which the insertion
  * should be performed.
- * @param {engine.view.DocumentFragment} content The content to insert.
+ * @param {engine.model.DocumentFragment} content The content to insert.
  * @param {engine.model.Selection} selection Selection into which the content should be inserted.
  * @param {engine.model.Batch} [batch] Batch to which deltas will be added. If not specified, then
  * changes will be added to a new batch.
  */
-export default function insert( dataController, content, selection, batch ) {
+export default function insertContent( dataController, content, selection, batch ) {
 	if ( !batch ) {
 		batch = dataController.model.batch();
 	}
@@ -39,19 +37,9 @@ export default function insert( dataController, content, selection, batch ) {
 		} );
 	}
 
-	// Convert the pasted content to a model document fragment.
-	// Convertion is contextual, but in this case we need an "all allowed" context and for that
-	// we use the $clipboardHolder item.
-	const modelFragment = dataController.viewToModel.convert( content, {
-		context: [ '$clipboardHolder' ]
-	} );
-
-	// We'll be debugging this dozens of times still.
-	// console.log( stringifyModel( modelFragment ) );
-
 	const insertion = new Insertion( dataController, batch, selection.anchor );
 
-	insertion.handleNodes( modelFragment.getChildren(), {
+	insertion.handleNodes( content.getChildren(), {
 		// The set of children being inserted is the only set in this context
 		// so it's the first and last (it's a hack ;)).
 		isFirst: true,
@@ -71,16 +59,22 @@ class Insertion {
 	constructor( dataController, batch, position ) {
 		/**
 		 * The data controller in context of which the insertion should be performed.
+		 *
+		 * @member {engine.controller.DataController} #dataController
 		 */
 		this.dataController = dataController;
 
 		/**
 		 * Batch to which deltas will be added.
+		 *
+		 * @member {engine.model.Batch} #batch
 		 */
 		this.batch = batch;
 
 		/**
 		 * The position at which (or near which) the next node will be inserted.
+		 *
+		 * @member {engine.model.Position} #position
 		 */
 		this.position = position;
 
@@ -91,11 +85,16 @@ class Insertion {
 		 *		<p>x</p><p>^y</p> + <p>z</p> (can merge to <p>y</p>)
 		 *		<p>x^y</p> + <p>z</p> (can merge to <p>xy</p> which will be split during the action,
 		 *								so both its pieces will be added to this set)
+		 *
+		 *
+		 * @member {Set} #canMergeWith
 		 */
 		this.canMergeWith = new Set( [ this.position.parent ] );
 
 		/**
 		 * Schema of the model.
+		 *
+		 * @member {engine.model.Schema} #schema
 		 */
 		this.schema = dataController.model.schema;
 	}
@@ -152,7 +151,7 @@ class Insertion {
 	 * @param {Boolean} context.isFirst Whether the given node is the first one in the content to be inserted.
 	 * @param {Boolean} context.isLast Whether the given node is the last one in the content to be inserted.
 	 */
-	_handleNode( node, context = {} ) {
+	_handleNode( node, context ) {
 		// Let's handle object in a special way.
 		// * They should never be merged with other elements.
 		// * If they are not allowed in any of the selection ancestors, they could be either autoparagraphed or totally removed.

+ 9 - 11
packages/ckeditor5-engine/tests/controller/datacontroller.js

@@ -3,8 +3,6 @@
  * For licensing, see LICENSE.md.
  */
 
-/* bender-tags: view */
-
 import ModelDocument from 'ckeditor5/engine/model/document.js';
 import DataController from 'ckeditor5/engine/controller/datacontroller.js';
 import HtmlDataProcessor from 'ckeditor5/engine/dataprocessor/htmldataprocessor.js';
@@ -12,8 +10,8 @@ import HtmlDataProcessor from 'ckeditor5/engine/dataprocessor/htmldataprocessor.
 import buildViewConverter  from 'ckeditor5/engine/conversion/buildviewconverter.js';
 import buildModelConverter  from 'ckeditor5/engine/conversion/buildmodelconverter.js';
 
-import ViewDocumentFragment from 'ckeditor5/engine/view/documentfragment.js';
-import ViewText from 'ckeditor5/engine/view/text.js';
+import ModelDocumentFragment from 'ckeditor5/engine/model/documentfragment.js';
+import ModelText from 'ckeditor5/engine/model/text.js';
 
 import { getData, setData, stringify, parse } from 'ckeditor5/engine/dev-utils/model.js';
 
@@ -43,13 +41,13 @@ describe( 'DataController', () => {
 
 		it( 'should add insertContent listener', () => {
 			const batch = modelDocument.batch();
-			const content = new ViewDocumentFragment( [ new ViewText( 'x' ) ] );
+			const content = new ModelDocumentFragment( [ new ModelText( 'x' ) ] );
 
 			schema.registerItem( 'paragraph', '$block' );
 
 			setData( modelDocument, '<paragraph>a[]b</paragraph>' );
 
-			data.fire( 'insert', { content, selection: modelDocument.selection, batch } );
+			data.fire( 'insertContent', { content, selection: modelDocument.selection, batch } );
 
 			expect( getData( modelDocument ) ).to.equal( '<paragraph>ax[]b</paragraph>' );
 			expect( batch.deltas.length ).to.be.above( 0 );
@@ -270,15 +268,15 @@ describe( 'DataController', () => {
 		} );
 	} );
 
-	describe( 'insert', () => {
-		it( 'should fire the insert event', () => {
+	describe( 'insertContent', () => {
+		it( 'should fire the insertContent event', () => {
 			const spy = sinon.spy();
-			const content = new ViewDocumentFragment( [ new ViewText( 'x' ) ] );
+			const content = new ModelDocumentFragment( [ new ModelText( 'x' ) ] );
 			const batch = modelDocument.batch();
 
-			data.on( 'insert', spy );
+			data.on( 'insertContent', spy );
 
-			data.insert( content, modelDocument.selection, batch );
+			data.insertContent( content, modelDocument.selection, batch );
 
 			expect( spy.args[ 0 ][ 1 ] ).to.deep.equal( {
 				batch: batch,

+ 0 - 1
packages/ckeditor5-engine/tests/controller/editingcontroller.js

@@ -4,7 +4,6 @@
  */
 
 /* globals setTimeout, Range, document */
-/* bender-tags: view */
 
 import EmitterMixin from 'ckeditor5/utils/emittermixin.js';
 

+ 7 - 17
packages/ckeditor5-engine/tests/controller/insert.js → packages/ckeditor5-engine/tests/controller/insertcontent.js

@@ -3,15 +3,11 @@
  * For licensing, see LICENSE.md.
  */
 
-/* bender-tags: model */
-
 import Document from 'ckeditor5/engine/model/document.js';
 import DataController from 'ckeditor5/engine/controller/datacontroller.js';
-import insert from 'ckeditor5/engine/controller/insert.js';
+import insertContent from 'ckeditor5/engine/controller/insertcontent.js';
 
-import ViewDocumentFragment from 'ckeditor5/engine/view/documentfragment.js';
-import ViewText from 'ckeditor5/engine/view/text.js';
-import ModelDocumentFragment from 'ckeditor5/engine/model/documentfragment.js';
+import DocumentFragment from 'ckeditor5/engine/model/documentfragment.js';
 import Text from 'ckeditor5/engine/model/text.js';
 
 import { setData, getData, parse } from 'ckeditor5/engine/dev-utils/model.js';
@@ -19,7 +15,7 @@ import { setData, getData, parse } from 'ckeditor5/engine/dev-utils/model.js';
 describe( 'DataController', () => {
 	let doc, dataController;
 
-	describe( 'insert', () => {
+	describe( 'insertContent', () => {
 		it( 'uses the passed batch', () => {
 			doc = new Document();
 			doc.createRoot();
@@ -31,7 +27,7 @@ describe( 'DataController', () => {
 
 			setData( doc, 'x[]x' );
 
-			insert( dataController, new ViewDocumentFragment( [ new ViewText( 'a' ) ] ), doc.selection, batch );
+			insertContent( dataController, new DocumentFragment( [ new Text( 'a' ) ] ), doc.selection, batch );
 
 			expect( batch.deltas.length ).to.be.above( 0 );
 		} );
@@ -540,16 +536,10 @@ describe( 'DataController', () => {
 			} );
 		}
 
-		if ( !( content instanceof ModelDocumentFragment ) ) {
-			content = new ModelDocumentFragment( [ content ] );
+		if ( !( content instanceof DocumentFragment ) ) {
+			content = new DocumentFragment( [ content ] );
 		}
 
-		// Override the convertion so we get exactly the model that we defined in the content param.
-		// This way we avoid the need to write converters for everything we want to test.
-		dataController.viewToModel.convert = () => {
-			return content;
-		};
-
-		insert( dataController, new ViewDocumentFragment(), doc.selection );
+		insertContent( dataController, content, doc.selection );
 	}
 } );