AppFlowy-IO / AppFlowy-IO/appflowy-editor

[Bug] deleteNodes and insertNodes in the same transactions leads to incorrect item order

Đang mở
#1,122 0 bình luận 0 reaction 0 người được giao Xem trên GitHub
Ngôn ngữ chính
Dart
Star
684
Fork
329
Chỉ số merge pull request
Không có pull request nào được merge trong 30 ngày

Mô tả

### Bug Description

Clearing a document with `deleteNode` and then adding replacing the content with `insertNodes` messes up the order of the nodes inserted if done in the same transaction.

### How to Reproduce

I added two tests in `transaction_test.dart`, which show the error. The first works as expected, the second fails because items are added in the wrong order:

```dart
test('insertNodes', () async {
final n1 = Node(type: 'paragraph-1');
final n2 = Node(type: 'paragraph-2');
final n3 = Node(type: 'paragraph-3');

final editorState = EditorState(document: Document.blank());
expect(editorState.document.root.children.length, 0);

final transaction = editorState.transaction;
transaction.insertNodes([0], [n1, n2, n3]);
await editorState.apply(transaction);

expect(editorState.document.root.children.length, 3);
expect(editorState.document.root.children[0].type, 'paragraph-1');
expect(editorState.document.root.children[1].type, 'paragraph-2');
expect(editorState.document.root.children[2].type, 'paragraph-3');
});

test('replacing Nodes', () async {
final n1 = Node(type: 'paragraph-1');
final n2 = Node(type: 'paragraph-2');
final n3 = Node(type: 'paragraph-3');
final start = Document.blank()
..insert([0], [paragraphNode(text: 'Initial content')]);

final editorState = EditorState(document: start);
expect(editorState.document.root.children.length, 1);

final transaction = editorState.transaction;
transaction.deleteNode(editorState.document.root.children.first);
transaction.insertNodes([0], [n1, n2, n3]);
await editorState.apply(transaction);

expect(editorState.document.root.children.length, 3);
expect(editorState.document.root.children[0].type, 'paragraph-1');
expect(editorState.document.root.children[1].type, 'paragraph-2');
expect(editorState.document.root.children[2].type, 'paragraph-3');
});
```

### Expected Behavior

The items should have the correct order.

### Operating System

Linux

### AppFlowy Editor Version(s)

5.2.0 / `main`

### Screenshots

n/a

### Additional Context

just applying them as two separate transactions seems to work fine.

Hướng dẫn đóng góp

Chưa lập chỉ mục được hướng dẫn đóng góp cho kho mã nguồn này

Đánh giá

Issue này chưa được đánh giá.

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.