Преглед изворни кода

feat: notify transaction instead of operations

Lucas.Xu пре 2 година
родитељ
комит
71b1769eee

+ 2 - 2
frontend/app_flowy/packages/appflowy_editor/example/lib/main.dart

@@ -109,8 +109,8 @@ class _MyHomePageState extends State<MyHomePage> {
             ..handler = (message) {
               debugPrint(message);
             };
-          _editorState!.operationStream.listen((event) {
-            debugPrint('Operation: ${event.toJson()}');
+          _editorState!.transactionStream.listen((event) {
+            debugPrint('Transaction: ${event.toJson()}');
           });
           return Container(
             color: darkMode ? Colors.black : Colors.white,

+ 5 - 4
frontend/app_flowy/packages/appflowy_editor/lib/src/editor_state.dart

@@ -9,7 +9,7 @@ import 'package:appflowy_editor/src/core/location/selection.dart';
 import 'package:appflowy_editor/src/core/document/document.dart';
 import 'package:appflowy_editor/src/core/transform/operation.dart';
 import 'package:appflowy_editor/src/core/transform/transaction.dart';
-import 'package:appflowy_editor/src/undo_manager.dart';
+import 'package:appflowy_editor/src/history/undo_manager.dart';
 
 class ApplyOptions {
   /// This flag indicates that
@@ -63,8 +63,8 @@ class EditorState {
   EditorStyle editorStyle = EditorStyle.defaultStyle();
 
   /// Operation stream.
-  Stream<Operation> get operationStream => _observer.stream;
-  final StreamController<Operation> _observer = StreamController.broadcast();
+  Stream<Transaction> get transactionStream => _observer.stream;
+  final StreamController<Transaction> _observer = StreamController.broadcast();
 
   final UndoManager undoManager = UndoManager();
   Selection? _cursorSelection;
@@ -140,6 +140,8 @@ class EditorState {
       _applyOperation(op);
     }
 
+    _observer.add(transaction);
+
     WidgetsBinding.instance.addPostFrameCallback((_) {
       updateCursorSelection(transaction.afterSelection);
     });
@@ -187,6 +189,5 @@ class EditorState {
     } else if (op is UpdateTextOperation) {
       document.updateText(op.path, op.delta);
     }
-    _observer.add(op);
   }
 }

+ 0 - 0
frontend/app_flowy/packages/appflowy_editor/lib/src/undo_manager.dart → frontend/app_flowy/packages/appflowy_editor/lib/src/history/undo_manager.dart


+ 1 - 1
frontend/app_flowy/packages/appflowy_editor/test/legacy/undo_manager_test.dart

@@ -1,6 +1,6 @@
 import 'dart:collection';
 import 'package:appflowy_editor/appflowy_editor.dart';
-import 'package:appflowy_editor/src/undo_manager.dart';
+import 'package:appflowy_editor/src/history/undo_manager.dart';
 import 'package:flutter_test/flutter_test.dart';
 
 void main() async {