| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101 |
- /**
- * @license Copyright (c) 2003-2017, CKSource - Frederico Knabben. All rights reserved.
- * For licensing, see LICENSE.md.
- */
- /**
- * @module engine/model/delta/insertdelta
- */
- import Delta from './delta';
- import DeltaFactory from './deltafactory';
- import RemoveDelta from './removedelta';
- import { register } from '../batch';
- import InsertOperation from '../operation/insertoperation';
- /**
- * @classdesc
- * To provide specific OT behavior and better collisions solving, the {@link module:engine/model/batch~Batch#insert Batch#insert} method
- * uses the `InsertDelta` class which inherits from the `Delta` class and may overwrite some methods.
- */
- export default class InsertDelta extends Delta {
- /**
- * @inheritDoc
- */
- get type() {
- return 'insert';
- }
- /**
- * Position where the delta inserts nodes or `null` if there are no operations in the delta.
- *
- * @readonly
- * @type {module:engine/model/position~Position|null}
- */
- get position() {
- return this._insertOperation ? this._insertOperation.position : null;
- }
- /**
- * Node list containing all the nodes inserted by the delta or `null` if there are no operations in the delta.
- *
- * @readonly
- * @type {module:engine/model/nodelist~NodeList|null}
- */
- get nodes() {
- return this._insertOperation ? this._insertOperation.nodes : null;
- }
- /**
- * Insert operation that is saved in this delta or `null` if there are no operations in the delta.
- *
- * @readonly
- * @protected
- * @type {module:engine/model/operation/insertoperation~InsertOperation|null}
- */
- get _insertOperation() {
- return this.operations[ 0 ] || null;
- }
- /**
- * @inheritDoc
- */
- get _reverseDeltaClass() {
- return RemoveDelta;
- }
- /**
- * @inheritDoc
- */
- static get className() {
- return 'engine.model.delta.InsertDelta';
- }
- /**
- * @inheritDoc
- */
- static get _priority() {
- return 20;
- }
- }
- /**
- * Inserts a node or nodes at the given position.
- *
- * @chainable
- * @method module:engine/model/batch~Batch#insert
- * @param {module:engine/model/position~Position} position Position of insertion.
- * @param {module:engine/model/node~NodeSet} nodes The list of nodes to be inserted.
- */
- register( 'insert', function( position, nodes ) {
- const delta = new InsertDelta();
- const insert = new InsertOperation( position, nodes, this.document.version );
- this.addDelta( delta );
- delta.addOperation( insert );
- this.document.applyOperation( insert );
- return this;
- } );
- DeltaFactory.register( InsertDelta );
|