selection.dart 496 B

123456789101112131415161718192021222324252627
  1. import './position.dart';
  2. class Selection {
  3. final Position start;
  4. final Position end;
  5. Selection({
  6. required this.start,
  7. required this.end,
  8. });
  9. factory Selection.collapsed(Position pos) {
  10. return Selection(start: pos, end: pos);
  11. }
  12. Selection collapse({bool atStart = false}) {
  13. if (atStart) {
  14. return Selection(start: start, end: start);
  15. } else {
  16. return Selection(start: end, end: end);
  17. }
  18. }
  19. bool isCollapsed() {
  20. return start == end;
  21. }
  22. }