removeoperation.js 1.4 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/operation/moveoperation',
  8. 'document/position',
  9. 'document/operation/reinsertoperation'
  10. ], ( MoveOperation, Position ) => {
  11. /**
  12. * Operation to remove a range of nodes.
  13. *
  14. * @class document.operation.RemoveOperation
  15. */
  16. class RemoveOperation extends MoveOperation {
  17. /**
  18. * Creates a remove operation.
  19. *
  20. * @param {document.Position} position Position before the first node to remove.
  21. * @param {Number} howMany How many nodes to remove.
  22. * @param {Number} baseVersion {@link document.Document#version} on which operation can be applied.
  23. * @constructor
  24. */
  25. constructor( position, howMany, baseVersion ) {
  26. const graveyard = position.root.document._graveyard;
  27. // Position in a graveyard where nodes were moved.
  28. const graveyardPosition = Position.createFromParentAndOffset( graveyard, 0 );
  29. super( position, graveyardPosition, howMany, baseVersion );
  30. }
  31. getReversed() {
  32. // Because of circular dependencies we need to re-require reinsert operation here.
  33. const ReinsertOperation = CKEDITOR.require( 'document/operation/reinsertoperation' );
  34. return new ReinsertOperation( this.targetPosition, this.sourcePosition, this.howMany, this.baseVersion + 1 );
  35. }
  36. }
  37. return RemoveOperation;
  38. } );