insertdelta.js 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940
  1. /**
  2. * @license Copyright (c) 2003-2016, CKSource - Frederico Knabben. All rights reserved.
  3. * For licensing, see LICENSE.md.
  4. */
  5. 'use strict';
  6. import Delta from './delta.js';
  7. import { register } from '../batch-base.js';
  8. import InsertOperation from '../operation/insertoperation.js';
  9. /**
  10. * To provide specific OT behavior and better collisions solving, the {@link treeModel.Batch#insert} method
  11. * uses the `InsertDelta` class which inherits from the `Delta` class and may overwrite some methods.
  12. *
  13. * @class treeModel.delta.InsertDelta
  14. */
  15. export default class InsertDelta extends Delta {}
  16. /**
  17. * Inserts a node or nodes at the given position.
  18. *
  19. * @chainable
  20. * @memberOf treeModel.Batch
  21. * @method insert
  22. * @param {treeModel.Position} position Position of insertion.
  23. * @param {treeModel.NodeSet} nodes The list of nodes to be inserted.
  24. * List of nodes can be of any type accepted by the {@link treeModel.NodeList} constructor.
  25. */
  26. register( 'insert', function( position, nodes ) {
  27. const delta = new InsertDelta();
  28. const operation = new InsertOperation( position, nodes, this.doc.version );
  29. this.doc.applyOperation( operation );
  30. delta.addOperation( operation );
  31. this.addDelta( delta );
  32. return this;
  33. } );