8
0

range.js 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  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( [ 'document/positioniterator' ], function( PositionIterator ) {
  7. /**
  8. * Range class. Range is iterable.
  9. *
  10. * @class document.Range
  11. */
  12. class Range {
  13. /**
  14. * Creates a range.
  15. *
  16. * @param {document.Position} start Start position.
  17. * @param {document.Position} end End position.
  18. * @constructor
  19. */
  20. constructor( start, end ) {
  21. /**
  22. * Start position.
  23. *
  24. * @property {document.Position}
  25. */
  26. this.start = start;
  27. /**
  28. * End position.
  29. *
  30. * @property {document.Position}
  31. */
  32. this.end = end;
  33. }
  34. /**
  35. * Two ranges equal if their start and end positions equal.
  36. *
  37. * @param {document.Range} otherRange Range to compare with.
  38. * @returns {Boolean} True if ranges equal.
  39. */
  40. isEqual( otherRange ) {
  41. return this.start.isEqual( otherRange.start ) && this.end.isEqual( otherRange.end );
  42. }
  43. /**
  44. * Range iterator.
  45. *
  46. * @see document.PositionIterator
  47. */
  48. [ Symbol.iterator ]() {
  49. return new PositionIterator( this );
  50. }
  51. }
  52. return Range;
  53. } );