Open miguelcmedeiros opened 1 day ago
Cc @matthew-carroll
@miguelcmedeiros What's the expected behavior these situations:
Non-deletable node at the end of the document: should an empty node be inserted as the first node? Should the document contain only the non-deletable node and no selection?
Non-deletable node at the start of the document: should an empty node be inserted as the last node? Should the document contain only the non-deletable node and no selection?
When all content in the document is selected using CMD+A and then pressing delete or backspace, it will throw exceptions if there is a non-deletable node at the start and/or end of the document. Here are 2 tests that reproduce this issue, one for each case:
Non-deletable node at the end of the document
test that reproduces issue
```dart testWidgetsOnApple( 'selects all when CMD+A is pressed with a two-node document', (tester) async { await tester // .createDocument() .withCustomContent( MutableDocument( nodes: [ ParagraphNode( id: '1', text: AttributedText('This is some text'), ), HorizontalRuleNode(id: '2'), ], ), ) .pump(); await tester.placeCaretInParagraph("1", 0); // Select all content await tester.pressCmdA(); // Ensure everything is selected. expect( SuperEditorInspector.findDocumentSelection(), const DocumentSelection( base: DocumentPosition( nodeId: '1', nodePosition: TextNodePosition(offset: 0), ), extent: DocumentPosition( nodeId: '2', nodePosition: UpstreamDownstreamNodePosition.downstream(), ), ), ); await tester.pressDelete(); }, ); ```exception
``` ══╡ EXCEPTION CAUGHT BY FOUNDATION LIBRARY ╞════════════════════════════════════════════════════════ The following _TypeError was thrown while dispatching notifications for PausableValueNotifierNon-deletable node at the start of the document
test that reproduces issue
```dart testWidgetsOnApple( 'selects all when CMD+A is pressed with a two-node document', (tester) async { await tester // .createDocument() .withCustomContent( MutableDocument( nodes: [ HorizontalRuleNode(id: '1'), ParagraphNode( id: '2', text: AttributedText('This is some text'), ), ], ), ) .pump(); await tester.placeCaretInParagraph("2", 0); // Select all content await tester.pressCmdA(); // Ensure everything is selected. expect( SuperEditorInspector.findDocumentSelection(), const DocumentSelection( base: DocumentPosition( nodeId: '1', nodePosition: UpstreamDownstreamNodePosition.upstream(), ), extent: DocumentPosition( nodeId: '2', nodePosition: TextNodePosition(offset: 17), ), ), ); await tester.pressDelete(); }, ); ```exception
``` ══╡ EXCEPTION CAUGHT BY FOUNDATION LIBRARY ╞════════════════════════════════════════════════════════ The following _Exception was thrown while dispatching notifications for PausableValueNotifier