operation.dart 1.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. import 'package:flowy_editor/document/path.dart';
  2. import 'package:flowy_editor/document/node.dart';
  3. abstract class Operation {
  4. Operation invert();
  5. }
  6. class InsertOperation extends Operation {
  7. final Path path;
  8. final Node value;
  9. InsertOperation({
  10. required this.path,
  11. required this.value,
  12. });
  13. @override
  14. Operation invert() {
  15. return DeleteOperation(path: path, removedValue: value);
  16. }
  17. }
  18. class UpdateOperation extends Operation {
  19. final Path path;
  20. final Attributes attributes;
  21. final Attributes oldAttributes;
  22. UpdateOperation({
  23. required this.path,
  24. required this.attributes,
  25. required this.oldAttributes,
  26. });
  27. @override
  28. Operation invert() {
  29. return UpdateOperation(path: path, attributes: oldAttributes, oldAttributes: attributes);
  30. }
  31. }
  32. class DeleteOperation extends Operation {
  33. final Path path;
  34. final Node removedValue;
  35. DeleteOperation({
  36. required this.path,
  37. required this.removedValue,
  38. });
  39. @override
  40. Operation invert() {
  41. return InsertOperation(path: path, value: removedValue);
  42. }
  43. }