removedelta.js 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. /**
  2. * @license Copyright (c) 2003-2015, CKSource - Frederico Knabben. All rights reserved.
  3. * For licensing, see LICENSE.md.
  4. */
  5. 'use strict';
  6. CKEDITOR.define( [
  7. 'document/delta/delta',
  8. 'document/delta/register',
  9. 'document/operation/removeoperation'
  10. ], ( Delta, register, RemoveOperation ) => {
  11. /**
  12. * To provide specific OT behavior and better collisions solving, {@link document.Transaction#remove} method
  13. * uses the `RemoveDelta` class which inherits from the `Delta` class and may overwrite some methods.
  14. *
  15. * @class document.delta.RemoveDelta
  16. */
  17. class RemoveDelta extends Delta {}
  18. /**
  19. * Removes nodes starting from the given position.
  20. *
  21. * @chainable
  22. * @method remove
  23. * @memberOf document.Transaction
  24. * @param {document.Position} position Position before the first node to remove.
  25. * @param {Number} howMany How many nodes to remove.
  26. */
  27. register( 'remove', ( doc, transaction, position, howMany ) => {
  28. if ( typeof howMany !== 'number' ) {
  29. howMany = 1;
  30. }
  31. const delta = new RemoveDelta();
  32. const operation = new RemoveOperation( position, howMany, doc.version );
  33. doc.applyOperation( operation );
  34. delta.addOperation( operation );
  35. transaction.addDelta( delta );
  36. } );
  37. return RemoveDelta;
  38. } );