reinsertoperation.js 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  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 MoveOperation from './moveoperation.js';
  7. import RemoveOperation from './removeoperation.js';
  8. /**
  9. * Operation to reinsert previously removed nodes back to the non-graveyard root.
  10. * This is basically {@link core.treeModel.operation.MoveOperation} but it returns
  11. * {@link core.treeModel.operation.RemoveOperation} when reversed.
  12. *
  13. * With this class, we achieve two goals: by having separate classes it's easier to distinguish whether move
  14. * operation is actually a remove/reinsert operation and fire proper events. Also it
  15. * will be easier to expand if we need to change operation's behavior if it is remove/reinsert.
  16. *
  17. * @memberOf core.treeModel.operation
  18. * @extends core.treeModel.operation.Operation
  19. */
  20. export default class ReinsertOperation extends MoveOperation {
  21. /**
  22. * Position where re-inserted node will be inserted.
  23. *
  24. * @type {core.treeModel.Position}
  25. */
  26. get position() {
  27. return this.targetPosition;
  28. }
  29. set position( pos ) {
  30. this.targetPosition = pos;
  31. }
  32. get type() {
  33. return 'reinsert';
  34. }
  35. /**
  36. * @returns {core.treeModel.operation.RemoveOperation}
  37. */
  38. getReversed() {
  39. return new RemoveOperation( this.targetPosition, this.howMany, this.baseVersion + 1 );
  40. }
  41. }