Skip to content

Commit

Permalink
fix: undo failed in a nested list in a special case
Browse files Browse the repository at this point in the history
  • Loading branch information
LucasXu0 committed Sep 25, 2023
1 parent 7743620 commit 8ff2e7b
Show file tree
Hide file tree
Showing 2 changed files with 58 additions and 0 deletions.
3 changes: 3 additions & 0 deletions lib/src/core/document/node.dart
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,9 @@ final class Node extends ChangeNotifier with LinkedListEntry<Node> {
_cacheChildren = null;

if (_children.isEmpty) {
if (entry.list != null) {
entry.unlink();
}
_children.add(entry);
notifyListeners();
return;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,61 @@ void main() async {

await editor.dispose();
});

// Before
// Welcome to AppFlowy 0| <- cursor here
// Welcome to AppFlowy 0 - 1
//
// press enter key at the cursor position
// and then, press tab key to indent the empty line
// After
// Welcome to AppFlowy 0
// | <- cursor here
// Welcome to AppFlowy 0 - 1
//
// execute undo command
testWidgets('Undo the nested list', (tester) async {
const text0 = 'Welcome to AppFlowy 0';
const text01 = 'Welcome to AppFlowy 0 - 1';

// Welcome to AppFlowy 0
// |Welcome to AppFlowy 0 - 1
final editor = tester.editor
..addParagraph(initialText: text0)
..addParagraph(initialText: text01);

await editor.startTesting();
await editor.updateSelection(
Selection.collapsed(Position(path: [1], offset: 0)),
);
await editor.pressKey(key: LogicalKeyboardKey.tab);

// Welcome to AppFlowy 0|
// Welcome to AppFlowy 0 - 1
await editor.updateSelection(
Selection.collapsed(Position(path: [0], offset: text0.length)),
);
await editor.pressKey(character: '\n');
await editor.pressKey(key: LogicalKeyboardKey.tab);
await tester.pumpAndSettle();

expect(editor.nodeAtPath([0])!.delta!.toPlainText(), text0);
expect(editor.nodeAtPath([0, 0])!.delta!.toPlainText(), isEmpty);
expect(editor.nodeAtPath([0, 0, 0])!.delta!.toPlainText(), text01);

// first undo
await _pressUndoCommand(editor);
expect(editor.nodeAtPath([0])!.delta!.toPlainText(), text0);
expect(editor.nodeAtPath([1])!.delta!.toPlainText(), isEmpty);
expect(editor.nodeAtPath([1, 0])!.delta!.toPlainText(), text01);

// second undo
await _pressUndoCommand(editor);
expect(editor.nodeAtPath([0])!.delta!.toPlainText(), text0);
expect(editor.nodeAtPath([0, 0])!.delta!.toPlainText(), text01);

await editor.dispose();
});
});
}

Expand Down

0 comments on commit 8ff2e7b

Please sign in to comment.