reinsertoperation.js 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. /**
  2. * @license Copyright (c) 2003-2016, CKSource - Frederico Knabben. All rights reserved.
  3. * For licensing, see LICENSE.md.
  4. */
  5. /**
  6. * @module engine/model/operation/reinsertoperation
  7. */
  8. import MoveOperation from './moveoperation';
  9. import RemoveOperation from './removeoperation';
  10. /**
  11. * Operation to reinsert previously removed nodes back to the non-graveyard root. This operation acts like
  12. * {@link module:engine/model/operation/moveoperation~MoveOperation} but it returns
  13. * {@link module:engine/model/operation/removeoperation~RemoveOperation} when reversed
  14. * and fires different change event.
  15. */
  16. export default class ReinsertOperation extends MoveOperation {
  17. /**
  18. * Position where nodes will be re-inserted.
  19. *
  20. * @type {module:engine/model/position~Position}
  21. */
  22. get position() {
  23. return this.targetPosition;
  24. }
  25. /**
  26. * @param {module:engine/model/position~Position} pos
  27. */
  28. set position( pos ) {
  29. this.targetPosition = pos;
  30. }
  31. /**
  32. * @inheritDoc
  33. */
  34. get type() {
  35. return 'reinsert';
  36. }
  37. /**
  38. * @inheritDoc
  39. * @returns {module:engine/model/operation/removeoperation~RemoveOperation}
  40. */
  41. getReversed() {
  42. return new RemoveOperation( this.targetPosition, this.howMany, this.baseVersion + 1 );
  43. }
  44. /**
  45. * @inheritDoc
  46. */
  47. static get className() {
  48. return 'engine.model.operation.ReinsertOperation';
  49. }
  50. }