2022-10-09 23:53:18 +08:00
|
|
|
import 'package:appflowy_editor/src/core/document/path.dart';
|
2022-08-17 17:23:20 +08:00
|
|
|
|
|
|
|
|
class Position {
|
|
|
|
|
final Path path;
|
|
|
|
|
final int offset;
|
|
|
|
|
|
|
|
|
|
Position({
|
|
|
|
|
required this.path,
|
|
|
|
|
this.offset = 0,
|
|
|
|
|
});
|
|
|
|
|
|
2023-04-27 15:34:39 +08:00
|
|
|
Position.invalid()
|
|
|
|
|
: path = [-1],
|
|
|
|
|
offset = -1;
|
|
|
|
|
|
2023-03-09 14:38:54 +07:00
|
|
|
factory Position.fromJson(Map<String, dynamic> json) {
|
|
|
|
|
final path = Path.from(json['path'] as List);
|
|
|
|
|
final offset = json['offset'];
|
2023-03-24 13:59:03 +01:00
|
|
|
|
2023-03-09 14:38:54 +07:00
|
|
|
return Position(
|
|
|
|
|
path: path,
|
|
|
|
|
offset: offset ?? 0,
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
2022-08-17 17:23:20 +08:00
|
|
|
@override
|
|
|
|
|
bool operator ==(Object other) {
|
2022-10-10 09:59:12 +08:00
|
|
|
if (identical(this, other)) return true;
|
|
|
|
|
|
|
|
|
|
return other is Position &&
|
|
|
|
|
other.path.equals(path) &&
|
|
|
|
|
other.offset == offset;
|
2022-08-17 17:23:20 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@override
|
2022-10-10 09:59:12 +08:00
|
|
|
int get hashCode => Object.hash(offset, Object.hashAll(path));
|
|
|
|
|
|
|
|
|
|
@override
|
|
|
|
|
String toString() => 'path = $path, offset = $offset';
|
2022-08-17 17:23:20 +08:00
|
|
|
|
|
|
|
|
Position copyWith({Path? path, int? offset}) {
|
|
|
|
|
return Position(
|
|
|
|
|
path: path ?? this.path,
|
|
|
|
|
offset: offset ?? this.offset,
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Map<String, dynamic> toJson() {
|
|
|
|
|
return {
|
2022-10-10 09:59:12 +08:00
|
|
|
'path': path,
|
|
|
|
|
'offset': offset,
|
2022-08-17 17:23:20 +08:00
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
}
|