8
0

removeoperation.js 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  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/moveoperation',
  8. 'document/position',
  9. 'document/reinsertoperation'
  10. ], function( MoveOperation, Position ) {
  11. /**
  12. * Operation to remove a range of nodes.
  13. *
  14. * @class document.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. var graveyard = position.root.document._graveyard;
  27. /**
  28. * Position in a graveyard where nodes were moved.
  29. */
  30. var graveyardPosition = Position.createFromParentAndOffset( graveyard, 0 );
  31. super( position, graveyardPosition, howMany, baseVersion );
  32. }
  33. /**
  34. * See {@link document.Operation#getReversed}.
  35. */
  36. getReversed() {
  37. // Because of circular dependencies we need to re-require reinsert operation here.
  38. var ReinsertOperation = CKEDITOR.require( 'document/reinsertoperation' );
  39. return new ReinsertOperation( this.targetPosition, this.sourcePosition, this.howMany, this.baseVersion + 1 );
  40. }
  41. }
  42. return RemoveOperation;
  43. } );