appflowy-editor/lib/src/core/location/position.dart
Lucas 41335c54ae
chore: merge flutter 3_27_4 into main branch (#1228)
* chore: merge flutter/3_27_4 to main branch

* chore: code format

* fix: unit tests
2026-07-27 15:37:27 +08:00

53 lines
1 KiB
Dart

import 'package:appflowy_editor/src/core/document/path.dart';
class Position {
Position({
required this.path,
this.offset = 0,
});
Position.invalid()
: path = [-1],
offset = -1;
factory Position.fromJson(Map<String, dynamic> json) {
final path = Path.from(json['path'] as List);
final offset = json['offset'];
return Position(
path: path,
offset: offset ?? 0,
);
}
final Path path;
final int offset;
@override
bool operator ==(Object other) {
if (identical(this, other)) return true;
return other is Position &&
other.path.equals(path) &&
other.offset == offset;
}
@override
int get hashCode => Object.hash(offset, Object.hashAll(path));
@override
String toString() => 'path = $path, offset = $offset';
Position copyWith({Path? path, int? offset}) {
return Position(
path: path ?? this.path,
offset: offset ?? this.offset,
);
}
Map<String, dynamic> toJson() {
return {
'path': path,
'offset': offset,
};
}
}