insertdelta.js 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. /**
  2. * @license Copyright (c) 2003-2017, CKSource - Frederico Knabben. All rights reserved.
  3. * For licensing, see LICENSE.md.
  4. */
  5. /**
  6. * @module engine/model/delta/insertdelta
  7. */
  8. import Delta from './delta';
  9. import RemoveDelta from './removedelta';
  10. import DeltaFactory from './deltafactory';
  11. /**
  12. * To provide specific OT behavior and better collisions solving, the {@link module:engine/model/batch~Batch#insert Batch#insert} method
  13. * uses the `InsertDelta` class which inherits from the `Delta` class and may overwrite some methods.
  14. *
  15. * @extends module:engine/model/delta/delta~Delta
  16. */
  17. export default class InsertDelta extends Delta {
  18. /**
  19. * @inheritDoc
  20. */
  21. get type() {
  22. return 'insert';
  23. }
  24. /**
  25. * Position where the delta inserts nodes or `null` if there are no operations in the delta.
  26. *
  27. * @readonly
  28. * @type {module:engine/model/position~Position|null}
  29. */
  30. get position() {
  31. return this._insertOperation ? this._insertOperation.position : null;
  32. }
  33. /**
  34. * Node list containing all the nodes inserted by the delta or `null` if there are no operations in the delta.
  35. *
  36. * @readonly
  37. * @type {module:engine/model/nodelist~NodeList|null}
  38. */
  39. get nodes() {
  40. return this._insertOperation ? this._insertOperation.nodes : null;
  41. }
  42. /**
  43. * Insert operation that is saved in this delta or `null` if there are no operations in the delta.
  44. *
  45. * @readonly
  46. * @protected
  47. * @type {module:engine/model/operation/insertoperation~InsertOperation|null}
  48. */
  49. get _insertOperation() {
  50. return this.operations[ 0 ] || null;
  51. }
  52. /**
  53. * @inheritDoc
  54. */
  55. get _reverseDeltaClass() {
  56. return RemoveDelta;
  57. }
  58. /**
  59. * @inheritDoc
  60. */
  61. static get className() {
  62. return 'engine.model.delta.InsertDelta';
  63. }
  64. }
  65. DeltaFactory.register( InsertDelta );