operation.dart 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  1. import 'package:flowy_editor/document/path.dart';
  2. import 'package:flowy_editor/document/node.dart';
  3. import 'package:flowy_editor/document/text_delta.dart';
  4. import 'package:flowy_editor/document/attributes.dart';
  5. abstract class Operation {
  6. Operation invert();
  7. }
  8. class InsertOperation extends Operation {
  9. final Path path;
  10. final Node value;
  11. InsertOperation({
  12. required this.path,
  13. required this.value,
  14. });
  15. @override
  16. Operation invert() {
  17. return DeleteOperation(
  18. path: path,
  19. removedValue: value,
  20. );
  21. }
  22. }
  23. class UpdateOperation extends Operation {
  24. final Path path;
  25. final Attributes attributes;
  26. final Attributes oldAttributes;
  27. UpdateOperation({
  28. required this.path,
  29. required this.attributes,
  30. required this.oldAttributes,
  31. });
  32. @override
  33. Operation invert() {
  34. return UpdateOperation(
  35. path: path,
  36. attributes: oldAttributes,
  37. oldAttributes: attributes,
  38. );
  39. }
  40. }
  41. class DeleteOperation extends Operation {
  42. final Path path;
  43. final Node removedValue;
  44. DeleteOperation({
  45. required this.path,
  46. required this.removedValue,
  47. });
  48. @override
  49. Operation invert() {
  50. return InsertOperation(
  51. path: path,
  52. value: removedValue,
  53. );
  54. }
  55. }
  56. class TextEditOperation extends Operation {
  57. final Path path;
  58. final Delta delta;
  59. TextEditOperation({
  60. required this.path,
  61. required this.delta,
  62. });
  63. @override
  64. Operation invert() {
  65. return TextEditOperation(path: path, delta: delta);
  66. }
  67. }