@@ -4,10 +4,9 @@ import 'package:attributed_text/attributed_text.dart';
44import 'package:flutter/services.dart' ;
55import 'package:super_editor/src/core/document.dart' ;
66import 'package:super_editor/src/core/document_composer.dart' ;
7- import 'package:super_editor/src/core/editor.dart' ;
87import 'package:super_editor/src/core/document_selection.dart' ;
8+ import 'package:super_editor/src/core/editor.dart' ;
99import 'package:super_editor/src/default_editor/box_component.dart' ;
10- import 'package:super_editor/src/default_editor/common_editor_operations.dart' ;
1110import 'package:super_editor/src/default_editor/selection_upstream_downstream.dart' ;
1211import 'package:super_editor/src/default_editor/text.dart' ;
1312import 'package:super_editor/src/infrastructure/_logging.dart' ;
@@ -839,8 +838,6 @@ class DeleteContentCommand extends EditCommand {
839838 return ;
840839 }
841840
842- late final DocumentPosition caretPosition;
843-
844841 final startNode = document.getNode (normalizedRange.start);
845842 if (startNode == null ) {
846843 throw Exception ('Could not locate start node for DeleteSelectionCommand: ${normalizedRange .start }' );
@@ -894,11 +891,6 @@ class DeleteContentCommand extends EditCommand {
894891 ),
895892 );
896893 }
897-
898- caretPosition = DocumentPosition (
899- nodeId: startNode.id,
900- nodePosition: normalizedRange.start.nodePosition,
901- );
902894 }
903895
904896 if (endNode.isDeletable) {
@@ -969,7 +961,22 @@ class DeleteContentCommand extends EditCommand {
969961 )
970962 ]);
971963
972- caretPosition = DocumentPosition (nodeId: emptyParagraphId, nodePosition: const TextNodePosition (offset: 0 ));
964+ if (updateSelection) {
965+ executor.executeCommand (
966+ ChangeSelectionCommand (
967+ DocumentSelection .collapsed (
968+ position: DocumentPosition (
969+ nodeId: emptyParagraphId,
970+ nodePosition: const TextNodePosition (offset: 0 ),
971+ ),
972+ ),
973+ SelectionChangeType .deleteContent,
974+ SelectionReason .userInteraction,
975+ ),
976+ );
977+ }
978+
979+ return ;
973980 }
974981
975982 // The start/end nodes may have been deleted due to empty content.
@@ -985,18 +992,41 @@ class DeleteContentCommand extends EditCommand {
985992 // Neither of the end nodes are `TextNode`s, so there's nothing
986993 // for us to merge. We're done.
987994 if (updateSelection) {
988- executor.executeCommand (
989- ChangeSelectionCommand (
990- DocumentSelection .collapsed (position: caretPosition),
991- SelectionChangeType .deleteContent,
992- SelectionReason .userInteraction,
993- ),
994- );
995+ if (startNodeAfterDeletion == null || ! startNodeAfterDeletion.isDeletable) {
996+ executor.executeCommand (
997+ ChangeSelectionCommand (
998+ DocumentSelection .collapsed (
999+ position: DocumentPosition (
1000+ nodeId: endNodeAfterDeletion! .id,
1001+ nodePosition: endNodeAfterDeletion.beginningPosition,
1002+ ),
1003+ ),
1004+ SelectionChangeType .deleteContent,
1005+ SelectionReason .userInteraction,
1006+ ),
1007+ );
1008+ } else {
1009+ executor.executeCommand (
1010+ ChangeSelectionCommand (
1011+ DocumentSelection .collapsed (
1012+ position: DocumentPosition (
1013+ nodeId: startNodeAfterDeletion.id,
1014+ nodePosition: startNodeAfterDeletion.endPosition,
1015+ ),
1016+ ),
1017+ SelectionChangeType .deleteContent,
1018+ SelectionReason .userInteraction,
1019+ ),
1020+ );
1021+ }
9951022 }
9961023
9971024 return ;
9981025 }
9991026
1027+ // Now that the content has been deleted, and we know the starting and ending
1028+ // nodes are both text nodes, add the ending node's text to the starting node.
1029+ // Then delete the ending node.
10001030 _log.log ('DeleteSelectionCommand' , ' - combining last node text with first node text' );
10011031 executor.logChanges ([
10021032 DocumentEdit (
@@ -1023,15 +1053,16 @@ class DeleteContentCommand extends EditCommand {
10231053 )
10241054 ]);
10251055
1026- caretPosition = DocumentPosition (
1027- nodeId: startNodeAfterDeletion.id,
1028- nodePosition: TextNodePosition (offset: startNodeAfterDeletion.text.length),
1029- );
1030-
1056+ // (Maybe) update the editor selection after the deletion.
10311057 if (updateSelection) {
10321058 executor.executeCommand (
10331059 ChangeSelectionCommand (
1034- DocumentSelection .collapsed (position: caretPosition),
1060+ DocumentSelection .collapsed (
1061+ position: DocumentPosition (
1062+ nodeId: startNodeAfterDeletion.id,
1063+ nodePosition: startNodeAfterDeletion.endPosition,
1064+ ),
1065+ ),
10351066 SelectionChangeType .deleteContent,
10361067 SelectionReason .userInteraction,
10371068 ),
@@ -1463,10 +1494,10 @@ class DeleteSelectionCommand extends EditCommand {
14631494 }
14641495 }
14651496
1466- final newSelectionPosition = CommonEditorOperations .getDocumentPositionAfterExpandedDeletion (
1467- document: document,
1468- selection: selection,
1469- );
1497+ // final newSelectionPosition = CommonEditorOperations.getDocumentPositionAfterExpandedDeletion(
1498+ // document: document,
1499+ // selection: selection,
1500+ // );
14701501
14711502 executor.executeCommand (
14721503 DeleteContentCommand (
0 commit comments