mirror of
https://github.com/AppFlowy-IO/AppFlowy.git
synced 2024-08-30 18:12:39 +00:00
feat: transform operation in transaction builder
This commit is contained in:
parent
c72fead19c
commit
033410aacd
@ -31,7 +31,11 @@ class Node extends ChangeNotifier with LinkedListEntry<Node> {
|
|||||||
required this.children,
|
required this.children,
|
||||||
required this.attributes,
|
required this.attributes,
|
||||||
this.parent,
|
this.parent,
|
||||||
});
|
}) {
|
||||||
|
for (final child in children) {
|
||||||
|
child.parent = this;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
factory Node.fromJson(Map<String, Object> json) {
|
factory Node.fromJson(Map<String, Object> json) {
|
||||||
assert(json['type'] is String);
|
assert(json['type'] is String);
|
||||||
|
@ -141,5 +141,6 @@ Operation transformOperation(Operation a, Operation b) {
|
|||||||
final newPath = transformPath(a.path, b.path, -1);
|
final newPath = transformPath(a.path, b.path, -1);
|
||||||
return b.copyWithPath(newPath);
|
return b.copyWithPath(newPath);
|
||||||
}
|
}
|
||||||
|
// TODO: transform update and textedit
|
||||||
return b;
|
return b;
|
||||||
}
|
}
|
||||||
|
@ -96,6 +96,9 @@ class TransactionBuilder {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
for (var i = 0; i < operations.length; i++) {
|
||||||
|
op = transformOperation(operations[i], op);
|
||||||
|
}
|
||||||
operations.add(op);
|
operations.add(op);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -3,6 +3,10 @@ import 'dart:collection';
|
|||||||
import 'package:flowy_editor/document/node.dart';
|
import 'package:flowy_editor/document/node.dart';
|
||||||
import 'package:flutter_test/flutter_test.dart';
|
import 'package:flutter_test/flutter_test.dart';
|
||||||
import 'package:flowy_editor/operation/operation.dart';
|
import 'package:flowy_editor/operation/operation.dart';
|
||||||
|
import 'package:flowy_editor/operation/transaction_builder.dart';
|
||||||
|
import 'package:flowy_editor/editor_state.dart';
|
||||||
|
import 'package:flowy_editor/document/state_tree.dart';
|
||||||
|
import 'package:flowy_editor/render/render_plugins.dart';
|
||||||
|
|
||||||
void main() {
|
void main() {
|
||||||
group('transform path', () {
|
group('transform path', () {
|
||||||
@ -46,4 +50,33 @@ void main() {
|
|||||||
expect(t.path, [0, 1]);
|
expect(t.path, [0, 1]);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
test('transform transaction builder', () {
|
||||||
|
final item1 = Node(type: "node", attributes: {}, children: LinkedList());
|
||||||
|
final item2 = Node(type: "node", attributes: {}, children: LinkedList());
|
||||||
|
final item3 = Node(type: "node", attributes: {}, children: LinkedList());
|
||||||
|
final root = Node(
|
||||||
|
type: "root",
|
||||||
|
attributes: {},
|
||||||
|
children: LinkedList()
|
||||||
|
..addAll([
|
||||||
|
item1,
|
||||||
|
item2,
|
||||||
|
item3,
|
||||||
|
]));
|
||||||
|
final state = EditorState(
|
||||||
|
document: StateTree(root: root), renderPlugins: RenderPlugins());
|
||||||
|
|
||||||
|
expect(item1.path, [0]);
|
||||||
|
expect(item2.path, [1]);
|
||||||
|
expect(item3.path, [2]);
|
||||||
|
|
||||||
|
final tb = TransactionBuilder(state);
|
||||||
|
tb.deleteNode(item1);
|
||||||
|
tb.deleteNode(item2);
|
||||||
|
tb.deleteNode(item3);
|
||||||
|
final transaction = tb.finish();
|
||||||
|
expect(transaction.operations[0].path, [0]);
|
||||||
|
expect(transaction.operations[1].path, [0]);
|
||||||
|
expect(transaction.operations[2].path, [0]);
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user