123456789101112131415161718192021222324252627282930313233343536373839404142434445464748 |
- import 'package:flowy_editor/document/path.dart';
- import 'package:flowy_editor/document/position.dart';
- import 'package:flowy_editor/extensions/path_extensions.dart';
- class Selection {
- final Position start;
- final Position end;
- Selection({
- required this.start,
- required this.end,
- });
- Selection.single({
- required Path path,
- required int startOffset,
- int? endOffset,
- }) : start = Position(path: path, offset: startOffset),
- end = Position(path: path, offset: endOffset ?? startOffset);
- Selection.collapsed(Position position)
- : start = position,
- end = position;
- Selection collapse({bool atStart = false}) {
- if (atStart) {
- return Selection(start: start, end: start);
- } else {
- return Selection(start: end, end: end);
- }
- }
- bool get isCollapsed => start == end;
- bool get isUpward =>
- start.path >= end.path && !pathEquals(start.path, end.path);
- bool get isDownward =>
- start.path <= end.path && !pathEquals(start.path, end.path);
- Selection copyWith({Position? start, Position? end}) {
- return Selection(
- start: start ?? this.start,
- end: end ?? this.end,
- );
- }
- @override
- String toString() => '[Selection] start = $start, end = $end';
- }
|