range.dart 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. import 'package:xterm/src/core/buffer/cell_offset.dart';
  2. import 'package:xterm/src/core/buffer/segment.dart';
  3. abstract class BufferRange {
  4. final CellOffset begin;
  5. final CellOffset end;
  6. const BufferRange(this.begin, this.end);
  7. BufferRange.collapsed(this.begin) : end = begin;
  8. bool get isNormalized {
  9. return begin.isBefore(end) || begin.isEqual(end);
  10. }
  11. bool get isCollapsed {
  12. return begin.isEqual(end);
  13. }
  14. BufferRange get normalized;
  15. /// Convert this range to segments of single lines.
  16. Iterable<BufferSegment> toSegments();
  17. /// Returns true if the given[position] is within this range.
  18. bool contains(CellOffset position);
  19. /// Returns the smallest range that contains both this range and the given
  20. /// [range].
  21. BufferRange merge(BufferRange range);
  22. /// Returns the smallest range that contains both this range and the given
  23. /// [position].
  24. BufferRange extend(CellOffset position);
  25. @override
  26. operator ==(Object other) {
  27. if (identical(this, other)) {
  28. return true;
  29. }
  30. if (other is! BufferRange) {
  31. return false;
  32. }
  33. return begin == other.begin && end == other.end;
  34. }
  35. @override
  36. int get hashCode => begin.hashCode ^ end.hashCode;
  37. @override
  38. String toString() => 'Range($begin, $end)';
  39. }