range.js 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. /**
  2. * @license Copyright (c) 2003-2015, CKSource - Frederico Knabben. All rights reserved.
  3. * For licensing, see LICENSE.md.
  4. */
  5. 'use strict';
  6. import Position from './position.js';
  7. /**
  8. * Tree view range.
  9. *
  10. * @memberOf core.treeView
  11. * @extends core.treeView.Range
  12. */
  13. export default class Range {
  14. /**
  15. * Creates a range spanning from `start` position to `end` position.
  16. * **Note:** Constructor creates it's own {@link core.treeView.Position} instances basing on passed values.
  17. *
  18. * @param {core.treeView.Position} start Start position.
  19. * @param {core.treeView.Position} end End position.
  20. */
  21. constructor( start, end ) {
  22. /**
  23. * Start position.
  24. *
  25. * @public
  26. * @member {core.treeView.Position} core.treeModel.Range#start
  27. */
  28. this.start = Position.createFromPosition( start );
  29. /**
  30. * End position.
  31. *
  32. * @public
  33. * @member {core.treeView.Position} core.treeModel.Range#end
  34. */
  35. this.end = Position.createFromPosition( end );
  36. }
  37. /**
  38. * Two ranges equal if their start and end positions equal.
  39. *
  40. * @param {core.treeView.Range} otherRange Range to compare with.
  41. * @returns {Boolean} True if ranges equal.
  42. */
  43. isEqual( otherRange ) {
  44. return this == otherRange || ( this.start.isEqual( otherRange.start ) && this.end.isEqual( otherRange.end ) );
  45. }
  46. }