operation.dart 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  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(
  16. path: path,
  17. removedValue: value,
  18. );
  19. }
  20. }
  21. class UpdateOperation extends Operation {
  22. final Path path;
  23. final Attributes attributes;
  24. final Attributes oldAttributes;
  25. UpdateOperation({
  26. required this.path,
  27. required this.attributes,
  28. required this.oldAttributes,
  29. });
  30. @override
  31. Operation invert() {
  32. return UpdateOperation(
  33. path: path,
  34. attributes: oldAttributes,
  35. oldAttributes: attributes,
  36. );
  37. }
  38. }
  39. class DeleteOperation extends Operation {
  40. final Path path;
  41. final Node removedValue;
  42. DeleteOperation({
  43. required this.path,
  44. required this.removedValue,
  45. });
  46. @override
  47. Operation invert() {
  48. return InsertOperation(
  49. path: path,
  50. value: removedValue,
  51. );
  52. }
  53. }