Browse Source

Docs: Move documentation about changing selection to `model.insertContent()` from `insertContent()`.

Maciej Gołaszewski 7 years ago
parent
commit
464a2ef6fb

+ 13 - 0
packages/ckeditor5-engine/src/model/model.js

@@ -298,6 +298,19 @@ export default class Model {
 	 *
 	 *		editor.model.insertContent( modelFragment, editor.model.document.selection );
 	 *
+	 * If an instance of {module:engine/model/selection~Selection} is passed as `selectable` it will be modified
+	 * to the insertion selection (equal to a range to be selected after insertion).
+	 *
+	 *		// Insert text replacing given selection instance.
+	 *		const selection = new Selection( new Position( doc.getRoot(), [ 2 ] ), new Position( doc.getRoot(), [ 5 ] ) );
+	 *
+	 *		editor.model.change( ( writer ) => {
+	 *			editor.model.insertContent( model, writer.createText( 'x' ), selection );
+	 *
+	 *			// The selection contains a range to be selected - ie can be used to set selection.
+	 *			writer.setSelection( selection );
+	 *		} );
+	 *
 	 * @fires insertContent
 	 * @param {module:engine/model/documentfragment~DocumentFragment|module:engine/model/item~Item} content The content to insert.
 	 * @param {module:engine/model/selection~Selection|module:engine/model/documentselection~DocumentSelection|

+ 0 - 22
packages/ckeditor5-engine/src/model/utils/insertcontent.js

@@ -19,31 +19,9 @@ import Selection from '../selection';
  * Inserts content into the editor (specified selection) as one would expect the paste
  * functionality to work.
  *
- *		// Insert text at current document selection position.
- *		model.change( () => {
- *			insertContent( model, new Text( 'x' ) ); // equal to insertContent( model, new Text( 'x' ), editor.model.document.selection );
- *		} );
- *
- *		// Insert text at some position - model's selection will not be modified.
- *		model.change( () => {
- *			insertContent( model, new Text( 'x' ), new Position( doc.getRoot(), [ 2 ] ) );
- *		} );
- *
  * If an instance of {module:engine/model/selection~Selection} is passed as `selectable` it will be modified
  * to the insertion selection (equal to a range to be selected after insertion).
  *
- *		// Insert text replacing given selection instance.
- *		const selection = new Selection( new Position( doc.getRoot(), [ 2 ] ), new Position( doc.getRoot(), [ 5 ] ) );
- *
- *		model.change( () => {
- *			insertContent( model, new Text( 'x' ), selection );
- *		} );
- *
- *		// The selection contains a range to be selected - ie can be used to set selection.
- *		model.change( ( writer ) => {
- *			writer.setSelection( selection );
- *		} );
- *
  * **Note:** Use {@link module:engine/model/model~Model#insertContent} instead of this function.
  * This function is only exposed to be reusable in algorithms which change the {@link module:engine/model/model~Model#insertContent}
  * method's behavior.