diff --git a/lib/src/core/document/node.dart b/lib/src/core/document/node.dart index 7b1491031..470a80472 100644 --- a/lib/src/core/document/node.dart +++ b/lib/src/core/document/node.dart @@ -149,6 +149,9 @@ final class Node extends ChangeNotifier with LinkedListEntry { _cacheChildren = null; if (_children.isEmpty) { + if (entry.list != null) { + entry.unlink(); + } _children.add(entry); notifyListeners(); return; diff --git a/test/new/service/shortcuts/command_shortcut_events/undo_redo_command_test.dart b/test/new/service/shortcuts/command_shortcut_events/undo_redo_command_test.dart index db8a483a4..66affc3ab 100644 --- a/test/new/service/shortcuts/command_shortcut_events/undo_redo_command_test.dart +++ b/test/new/service/shortcuts/command_shortcut_events/undo_redo_command_test.dart @@ -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(); + }); }); }